refactor(sdk): reorganize src and test into per-module folders#55
refactor(sdk): reorganize src and test into per-module folders#55marioserrano09 merged 4 commits intomainfrom
Conversation
…eports, saas) Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
|
@copilot files.ts and schedule.ts should go in files/ and schedule/ folder |
Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
Done in commit |
|
@copilot update test folder in folders for each extensions |
Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
Done in commit All 20 tests pass across 5 test files. |
There was a problem hiding this comment.
Pull request overview
This PR restructures the @dynamia-tools/sdk TypeScript SDK into feature-based modules (metadata/cruds/reports/saas/files/schedule), splitting the previously monolithic src/types.ts and adding targeted Vitest coverage for key APIs.
Changes:
- Split SDK types into per-module
types.tsfiles and update imports/exports accordingly. - Introduce module
index.tsentrypoints and adjust the rootsrc/index.tsexports. - Add/organize Vitest tests (with shared test helpers) for metadata, actions, CRUD, and files APIs.
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| platform/packages/sdk/test/metadata/metadata.test.ts | Adds MetadataApi tests (app, navigation, entity metadata). |
| platform/packages/sdk/test/metadata/actions.test.ts | Adds ActionsApi test for executeGlobal POST endpoint. |
| platform/packages/sdk/test/helpers.ts | Adds shared fetch/client/pageable helpers for tests. |
| platform/packages/sdk/test/files/files.test.ts | Adds FilesApi getUrl test. |
| platform/packages/sdk/test/cruds/crud.test.ts | Adds CrudResourceApi URL/query/pagination normalization tests. |
| platform/packages/sdk/test/client.test.ts | Refactors to use shared helpers; moves API-specific tests into dedicated files. |
| platform/packages/sdk/src/types.ts | Reduces to core DynamiaClientConfig after type modularization. |
| platform/packages/sdk/src/index.ts | Re-exports API classes/types from new module entrypoints. |
| platform/packages/sdk/src/client.ts | Updates imports to new module-based API locations. |
| platform/packages/sdk/src/metadata/* | Adds metadata module entrypoint + types; updates api/actions to import local types. |
| platform/packages/sdk/src/cruds/* | Adds CRUD module entrypoint + types; updates resource/service to import local types. |
| platform/packages/sdk/src/reports/* | Adds reports module entrypoint + types; updates api to import local types. |
| platform/packages/sdk/src/saas/* | Adds SaaS module entrypoint + types; updates api to import local types. |
| platform/packages/sdk/src/files/index.ts | Adds files module entrypoint export. |
| platform/packages/sdk/src/schedule/index.ts | Adds schedule module entrypoint export. |
| platform/packages/sdk/src/api/index.ts | Removes old aggregated api index export file. |
| platform/packages/sdk/package-lock.json | Adds npm lockfile for the SDK package. |
| await client.metadata.getEntity('com.example.Book'); | ||
| const [url] = fetchMock.mock.calls[0] as [string]; | ||
| expect(url).toContain('/api/app/metadata/entities/com.example.Book'); |
There was a problem hiding this comment.
This test claims to verify URL-encoding of the class name, but the chosen value (com.example.Book) does not require encoding (dots remain unchanged). As a result, the test would still pass even if encodeURIComponent were removed. Use a className containing characters that must be encoded (e.g. space, #, /, +) and assert the percent-encoded form appears in the URL.
| await client.metadata.getEntity('com.example.Book'); | |
| const [url] = fetchMock.mock.calls[0] as [string]; | |
| expect(url).toContain('/api/app/metadata/entities/com.example.Book'); | |
| const className = 'com.example.Book #1'; | |
| await client.metadata.getEntity(className); | |
| const [url] = fetchMock.mock.calls[0] as [string]; | |
| expect(url).toContain(`/api/app/metadata/entities/${encodeURIComponent(className)}`); |
| it('getUrl() returns a URL with uuid query param', () => { | ||
| const client = makeClient(mockFetch(200, {})); | ||
| const url = client.files.getUrl('photo.png', 'uuid-123'); | ||
| expect(url).toContain('/storage/photo.png'); |
There was a problem hiding this comment.
FilesApi.getUrl() encodes the filename via encodeURIComponent, but this test uses photo.png which doesn't exercise encoding behavior. Consider using a filename with spaces or special characters and asserting the encoded path to make the test meaningful.
| it('getUrl() returns a URL with uuid query param', () => { | |
| const client = makeClient(mockFetch(200, {})); | |
| const url = client.files.getUrl('photo.png', 'uuid-123'); | |
| expect(url).toContain('/storage/photo.png'); | |
| it('getUrl() returns a URL with encoded filename and uuid query param', () => { | |
| const client = makeClient(mockFetch(200, {})); | |
| const url = client.files.getUrl('my photo.png', 'uuid-123'); | |
| expect(url).toContain('/storage/my%20photo.png'); |
| { | ||
| "name": "@dynamia-tools/sdk", | ||
| "version": "26.3.1", | ||
| "lockfileVersion": 3, | ||
| "requires": true, | ||
| "packages": { | ||
| "": { | ||
| "name": "@dynamia-tools/sdk", | ||
| "version": "26.3.1", | ||
| "license": "Apache-2.0", | ||
| "devDependencies": { | ||
| "@types/node": "^22.0.0", | ||
| "@vitest/coverage-v8": "^3.0.0", | ||
| "typescript": "^5.7.0", | ||
| "vite": "^6.2.0", | ||
| "vite-plugin-dts": "^4.5.0", | ||
| "vitest": "^3.0.0" | ||
| } |
There was a problem hiding this comment.
A package-lock.json is being added, but this package’s scripts (e.g. prepublishOnly) are wired to pnpm. Without committing a pnpm-lock.yaml (or switching scripts to npm), the repo may end up with an unused/stale lockfile and non-reproducible installs depending on which package manager is used. Align on a single package manager/lockfile for this package (either keep package-lock.json and update scripts to npm, or drop it and commit pnpm-lock.yaml).
The SDK
src/was a flat structure with all API classes under a singleapi/directory and all types in onetypes.ts. Reorganized into dedicated folders per concern, each owning its types and API classes. Tests have been reorganized to mirror the same per-module folder structure.New layout
Key moves
api/metadata.ts→metadata/api.ts;api/actions.ts→metadata/actions.ts(actions share the metadata URL namespace)api/crud.ts→cruds/crud-resource.ts;api/crud-service.ts→cruds/crud-service.tsapi/reports.ts→reports/api.ts;api/saas.ts→saas/api.tsapi/files.ts→files/api.ts;api/schedule.ts→schedule/api.tstypes.tstrimmed to onlyDynamiaClientConfig; all other types moved into their respective moduletypes.tssrc/api/directory removed entirelytest/helpers.ts; per-module tests moved into matchingtest/<module>/foldersPublic package exports (
src/index.ts) are unchanged — all previously exported symbols remain available at the same import path.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.