Skip to content

refactor(sdk): reorganize src and test into per-module folders#55

Merged
marioserrano09 merged 4 commits intomainfrom
copilot/organize-modules-and-extensions
Mar 11, 2026
Merged

refactor(sdk): reorganize src and test into per-module folders#55
marioserrano09 merged 4 commits intomainfrom
copilot/organize-modules-and-extensions

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

The SDK src/ was a flat structure with all API classes under a single api/ directory and all types in one types.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

src/
├── client.ts / http.ts / errors.ts / types.ts   # core (DynamiaClientConfig, HttpClient, etc.)
├── metadata/   api.ts · actions.ts · types.ts · index.ts
├── cruds/      crud-resource.ts · crud-service.ts · types.ts · index.ts
├── reports/    api.ts · types.ts · index.ts
├── saas/       api.ts · types.ts · index.ts
├── files/      api.ts · index.ts
└── schedule/   api.ts · index.ts

test/
├── helpers.ts                    # shared mockFetch / makeClient / rawPageResponse
├── client.test.ts                # DynamiaClient construction, errors, auth
├── metadata/
│   ├── metadata.test.ts
│   └── actions.test.ts
├── cruds/
│   └── crud.test.ts
└── files/
    └── files.test.ts

Key moves

  • api/metadata.tsmetadata/api.ts; api/actions.tsmetadata/actions.ts (actions share the metadata URL namespace)
  • api/crud.tscruds/crud-resource.ts; api/crud-service.tscruds/crud-service.ts
  • api/reports.tsreports/api.ts; api/saas.tssaas/api.ts
  • api/files.tsfiles/api.ts; api/schedule.tsschedule/api.ts
  • types.ts trimmed to only DynamiaClientConfig; all other types moved into their respective module types.ts
  • Old src/api/ directory removed entirely
  • Shared test helpers extracted into test/helpers.ts; per-module tests moved into matching test/<module>/ folders

Public package exports (src/index.ts) are unchanged — all previously exported symbols remain available at the same import path.

Original prompt

In platform/packages/sdk use a folder for each module or extention.

/metadata: with types and apis
/cruds: with types and api releated to crud rest api
/reports: for report extentions with its own types and api
/saas: for SaaS releated types and apis
/ for core stuff like client and utils.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…eports, saas)

Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor SDK structure by organizing modules and extensions refactor(sdk): reorganize src into per-module folders Mar 11, 2026
@marioserrano09
Copy link
Contributor

@copilot files.ts and schedule.ts should go in files/ and schedule/ folder

Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

@copilot files.ts and schedule.ts should go in files/ and schedule/ folder

Done in commit 7621850. Both files.ts and schedule.ts are now in src/files/ and src/schedule/ folders respectively, each with an api.ts and index.ts, consistent with the other module folders.

@marioserrano09
Copy link
Contributor

@copilot update test folder in folders for each extensions

Co-authored-by: marioserrano09 <5221275+marioserrano09@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

@copilot update test folder in folders for each extensions

Done in commit 01809bc. Tests are now split into per-module folders matching the src/ structure:

test/
├── helpers.ts                    # shared mockFetch / makeClient / rawPageResponse
├── client.test.ts                # DynamiaClient construction, errors, auth
├── metadata/
│   ├── metadata.test.ts          # MetadataApi tests
│   └── actions.test.ts           # ActionsApi tests
├── cruds/
│   └── crud.test.ts              # CrudResourceApi tests
└── files/
    └── files.test.ts             # FilesApi tests

All 20 tests pass across 5 test files.

Copilot AI changed the title refactor(sdk): reorganize src into per-module folders refactor(sdk): reorganize src and test into per-module folders Mar 11, 2026
@marioserrano09 marioserrano09 marked this pull request as ready for review March 11, 2026 21:19
Copilot AI review requested due to automatic review settings March 11, 2026 21:19
@marioserrano09 marioserrano09 merged commit 6670fb2 into main Mar 11, 2026
3 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts files and update imports/exports accordingly.
  • Introduce module index.ts entrypoints and adjust the root src/index.ts exports.
  • 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.

Comment on lines +30 to +32
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');
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)}`);

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +8
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');
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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');

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +18
{
"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"
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@marioserrano09 marioserrano09 deleted the copilot/organize-modules-and-extensions branch March 12, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants