@syncmatters/script-api 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Org connection uid → that connection's generated `Connection` type.
3
+ *
4
+ * Empty in this package. `sm types` / the web editor merge keys via
5
+ * `declare module '@syncmatters/script-api/connections/map'`.
6
+ */
7
+ export interface ConnectionMap {
8
+ }
@@ -30,8 +30,22 @@ Each file starts with:
30
30
 
31
31
  - Do **not** hand-edit snapshots to change mappings, schedules, or wiring.
32
32
  - Do **not** `sm push` snapshot paths — there is no push route for them today.
33
- - Do **not** treat snapshots as the source of truth for writes — the web UI (or future CLI sync
34
- commands) owns configuration changes.
33
+ - Do **not** treat snapshots as the source of truth for writes. Author mapping changes in
34
+ `changes/*.sync-changes.json`, preview with `sm sync draft <file>`, then stop — there is no
35
+ `sm sync push` yet. The web UI still owns applying configuration.
36
+
37
+ ## Preview drafts (`sm sync draft`)
38
+
39
+ Preview writes a second JSON tree (not a pull snapshot):
40
+
41
+ ```
42
+ syncs/<sync_uid>/sync.config.draft.json # existing sync, after the changeset
43
+ changes/<name>.draft.<handle>.json # created sync/group (`$` stripped)
44
+ ```
45
+
46
+ `$sm.generated_by` is `"sm sync draft"`. These files are evaluation output — never a `sm push`
47
+ payload. `sm pull` never deletes `*.draft.json` (rename+`--force` relocates them with the uid).
48
+ A rerun of `sm sync draft <file>` replaces `changes/<name>.draft.*.json` for that changeset stem.
35
49
 
36
50
  ## Refresh
37
51
 
@@ -41,5 +55,5 @@ Each file starts with:
41
55
  | `sm pull` | Scripts + snapshots (unless `--no-syncs`) |
42
56
  | `sm pull sync --force` | Overwrite locally modified **generated** snapshots |
43
57
 
44
- Missing `syncs:read` on the developer token: default pull warns and skips; `sm pull sync` exits
45
- 2 with mint-token guidance.
58
+ Missing `syncs:read` on the developer token: default pull warns and skips; `sm pull sync` and
59
+ `sm sync draft` exit 2 with mint-token guidance.
@@ -30,7 +30,7 @@ Prefer tokens **without execute scopes** for day-to-day edit/push work:
30
30
  | --- | --- |
31
31
  | `scripts:read` | pull, diff incoming |
32
32
  | `scripts:write` | push script files |
33
- | `syncs:read` | `sm pull sync`, sync snapshots |
33
+ | `syncs:read` | `sm pull sync`, sync snapshots, `sm sync draft` |
34
34
  | `connections:read` | `sm types`, connection resolution |
35
35
  | `scripts:execute` | **Only when running** `sm test` / connector features |
36
36
  | `syncs:execute` | Reserved; not needed for authoring |
@@ -48,7 +48,7 @@ If the CLI reports **403** with missing scope or "not available to developer tok
48
48
 
49
49
  Examples:
50
50
 
51
- - Missing `syncs:read` → cannot pull sync snapshots (`sm pull sync`).
51
+ - Missing `syncs:read` → cannot pull sync snapshots (`sm pull sync`) or preview a changeset (`sm sync draft`).
52
52
  - Missing `scripts:execute` → cannot run `sm test` (expected if using a read/write-only token).
53
53
 
54
54
  ## Non-interactive runs
package/lib/context.d.ts CHANGED
@@ -1,19 +1,27 @@
1
+ import type { ConnectionMap } from "@syncmatters/script-api/connections/map";
2
+ import type { SyncGroupMap } from "@syncmatters/script-api/syncGroups/map";
1
3
  import { Connection } from "./connection.js";
2
4
  import { SyncGroup } from "./sync-group.js";
3
5
  import { Logger } from "./logger.js";
4
6
  import { FileProvider } from "./utilities/file-provider/file-provider.js";
7
+ /**
8
+ * When the org map is empty (no `sm types` overlay), keep a string index so
9
+ * runners and tests still type `ctx.connections[name]`. Once keys are merged
10
+ * onto ConnectionMap / SyncGroupMap, those uids become typed factories.
11
+ */
12
+ export type ContextMapFactories<M, Fallback> = [keyof M] extends [never] ? {
13
+ [name: string]: () => Promise<Fallback>;
14
+ } : {
15
+ [P in keyof M]: () => Promise<M[P]>;
16
+ };
5
17
  /** Context is passed to the script to provide access to system services such as logging, connections, state and environment information */
6
18
  export interface Context {
7
19
  log: Logger;
8
20
  parameters: {
9
21
  [name: string]: any;
10
22
  };
11
- connections: {
12
- [name: string]: () => Promise<Connection>;
13
- };
14
- syncGroups: {
15
- [name: string]: () => Promise<SyncGroup>;
16
- };
23
+ connections: ContextMapFactories<ConnectionMap, Connection>;
24
+ syncGroups: ContextMapFactories<SyncGroupMap, SyncGroup>;
17
25
  state: {
18
26
  get(): Promise<any>;
19
27
  set(state: any): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncmatters/script-api",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "TypeScript type definitions for the SyncMatters script API (types only - scripts execute on the SyncMatters platform)",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -15,12 +15,20 @@
15
15
  "./api": {
16
16
  "types": "./api.d.ts",
17
17
  "default": "./index.js"
18
+ },
19
+ "./connections/map": {
20
+ "types": "./connections/map.d.ts",
21
+ "default": "./index.js"
22
+ },
23
+ "./syncGroups/map": {
24
+ "types": "./syncGroups/map.d.ts",
25
+ "default": "./index.js"
18
26
  }
19
27
  },
20
28
  "license": "MIT",
21
29
  "author": "SyncMatters",
22
30
  "homepage": "https://syncmatters.com",
23
- "typesContentHash": "5251aaa77076a0901c2b3221a4be5f4d9a9d9aeb572ef3e59f4952b31e9fffdf",
31
+ "typesContentHash": "6074e4b68cb636902e4d5a8962e71228571bd13fe17b0d186f35714addbd126e",
24
32
  "dependencies": {
25
33
  "@types/node": "*"
26
34
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Org sync-group uid → `SyncGroup`. Every key is the same runtime type;
3
+ * the map exists so `ctx.syncGroups.<uid>()` can complete.
4
+ *
5
+ * Empty in this package. `sm types` / the web editor merge keys via
6
+ * `declare module '@syncmatters/script-api/syncGroups/map'`.
7
+ */
8
+ export interface SyncGroupMap {
9
+ }