@notionhq/apps 0.0.17 → 0.0.18

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.
Files changed (44) hide show
  1. package/AGENTS.md +27 -0
  2. package/README.md +60 -35
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/notion-as-code/database.d.ts +88 -48
  6. package/dist/notion-as-code/database.d.ts.map +1 -1
  7. package/dist/notion-as-code/database.js +132 -45
  8. package/dist/notion-as-code/database.test.d.ts +2 -0
  9. package/dist/notion-as-code/database.test.d.ts.map +1 -0
  10. package/dist/notion-as-code/index.d.ts +2 -2
  11. package/dist/notion-as-code/index.d.ts.map +1 -1
  12. package/dist/notion-as-code/intents.d.ts +34 -2
  13. package/dist/notion-as-code/intents.d.ts.map +1 -1
  14. package/dist/notion-as-code/schema.d.ts +8 -4
  15. package/dist/notion-as-code/schema.d.ts.map +1 -1
  16. package/dist/notion-as-code/views.d.ts +29 -10
  17. package/dist/notion-as-code/views.d.ts.map +1 -1
  18. package/dist/sync.d.ts +33 -15
  19. package/dist/sync.d.ts.map +1 -1
  20. package/dist/sync.js +12 -0
  21. package/dist/workflow-state.d.ts +13 -0
  22. package/dist/workflow-state.d.ts.map +1 -0
  23. package/dist/workflow-state.js +107 -0
  24. package/dist/workflow.d.ts +48 -3
  25. package/dist/workflow.d.ts.map +1 -1
  26. package/dist/workflow.js +111 -4
  27. package/docs/BUILD.md +96 -0
  28. package/package.json +1 -1
  29. package/skills/notion-as-code/SKILL.md +81 -49
  30. package/skills/sync/SKILL.md +21 -18
  31. package/skills/workflow/SKILL.md +52 -3
  32. package/src/cli/build.test.ts +124 -64
  33. package/src/index.ts +1 -0
  34. package/src/notion-as-code/database.test.ts +661 -0
  35. package/src/notion-as-code/database.ts +344 -127
  36. package/src/notion-as-code/index.ts +16 -1
  37. package/src/notion-as-code/intents.ts +39 -2
  38. package/src/notion-as-code/schema.ts +11 -3
  39. package/src/notion-as-code/views.ts +29 -10
  40. package/src/sync.test.ts +295 -0
  41. package/src/sync.ts +85 -21
  42. package/src/workflow-state.ts +152 -0
  43. package/src/workflow.test.ts +329 -1
  44. package/src/workflow.ts +180 -6
package/AGENTS.md CHANGED
@@ -11,3 +11,30 @@ matching skill:
11
11
 
12
12
  Resolve these links relative to this package directory. Check the installed SDK
13
13
  declarations for current API details.
14
+
15
+ ## Pull requests for SDK changes
16
+
17
+ For a change to the public SDK, show the user-facing code change in the pull
18
+ request body. Put a short, complete example near the top:
19
+
20
+ ````md
21
+ ## User code
22
+
23
+ ### Before
24
+
25
+ ```ts
26
+ // Existing app code
27
+ ```
28
+
29
+ ### After
30
+
31
+ ```ts
32
+ // Updated app code
33
+ ```
34
+ ````
35
+
36
+ Use the same small example in both sections so reviewers can compare them
37
+ quickly. Include imports and the call that changed when they matter. Show
38
+ normal app code, not internal types, tests, generated files, or provisioning
39
+ output. Explain any required migration steps in plain language below the
40
+ example.
package/README.md CHANGED
@@ -116,22 +116,17 @@ Declare a database with Notion as Code, then pass one of its data-source handles
116
116
  import { database, sync } from "@notionhq/apps";
117
117
  import { Builder } from "@notionhq/apps/builder";
118
118
 
119
- const issues = database({
120
- resourceId: "issues-db",
121
- dataSources: [
122
- {
123
- resourceId: "issues-source",
124
- name: "GitHub Issues",
125
- properties: [
126
- { resourceId: "name", name: "Name", type: "title" },
127
- { resourceId: "github-id", name: "GitHub ID", type: "text" },
128
- ],
129
- },
130
- ],
119
+ const issues = database("issues-db", {
120
+ dataSourceResourceId: "issues-source",
121
+ name: "GitHub Issues",
122
+ schema: {
123
+ Name: { resourceId: "name", type: "title" },
124
+ "GitHub ID": { resourceId: "github-id", type: "text" },
125
+ },
131
126
  });
132
127
 
133
128
  export default sync({
134
- dataSource: issues.dataSources["issues-source"],
129
+ dataSource: issues.dataSource,
135
130
  primaryKey: "GitHub ID",
136
131
  handler: async () => ({
137
132
  changes: [
@@ -146,40 +141,70 @@ export default sync({
146
141
  ```
147
142
 
148
143
  Put each default-exported sync directly in `src/syncs/`. A primary key must be a title
149
- or text property. Do not include that property in an upsert: the SDK fills it from
150
- the change's `key`.
144
+ or text property. Each upsert must include at least one known non-primary-key schema
145
+ property, while any other non-primary-key properties may be omitted; unknown property keys
146
+ are rejected by TypeScript. Do not include the primary-key property in an upsert: the SDK
147
+ fills it from the change's `key`.
151
148
 
152
149
  ## Notion-as-Code databases
153
150
 
154
- Use `properties` to declare a database with one data source:
151
+ Use `schema` and an explicit `dataSourceResourceId` to declare a database with one data source:
155
152
 
156
153
  ```ts
157
154
  import { notion } from "@notionhq/apps/notion-as-code";
158
155
 
159
- const issues = notion.database({
160
- resourceId: "branch-check-issues",
156
+ const singleSourceIssues = notion.database("branch-check-issues", {
157
+ dataSourceResourceId: "branch-check-issues-source",
161
158
  name: "Issues",
162
- properties: [
163
- { resourceId: "issue-title", name: "Name", type: "title" },
164
- { resourceId: "issue-id", name: "ID", type: "text" },
165
- ],
159
+ schema: {
160
+ Name: { resourceId: "issue-title", type: "title" },
161
+ ID: { resourceId: "issue-id", type: "text" },
162
+ },
166
163
  });
167
164
  ```
168
165
 
169
- Pass `issues.dataSource` as the `dataSource` argument to `sync` from `@notionhq/apps`, or use
170
- `issues.dataSource.addPage(...)` to declare a page in the source. The database still exposes
171
- `dataSources` and `addView`.
166
+ Pass `singleSourceIssues.dataSource` as the `dataSource` argument to `sync` from `@notionhq/apps`, or use
167
+ `singleSourceIssues.dataSource.addPage(...)` to declare a page in the source. Both database forms expose `addView`.
168
+
169
+ For multiple sources, use `datasources` instead of the top-level `schema`:
170
+
171
+ ```ts
172
+ const issues = notion.database("issues-db", {
173
+ datasources: {
174
+ Issues: {
175
+ resourceId: "issues-source",
176
+ schema: {
177
+ Name: { resourceId: "issue-title", type: "title" },
178
+ "GitHub ID": { resourceId: "github-id", type: "text" },
179
+ },
180
+ },
181
+ },
182
+ });
172
183
 
173
- For explicit sources, keep using `notion.database({ resourceId, dataSources: [...] })`
174
- and access each source through `handle.dataSources[sourceResourceId]`.
175
- `properties` and `dataSources` are mutually exclusive. Both forms also work with
176
- page and teamspace `addDatabase` helpers.
184
+ issues.datasources.Issues.schema.Name;
185
+ ```
177
186
 
178
- The shorthand emits the existing database intent with one source named after the
179
- database and identified by `${resourceId}-source`. That ID must be globally unique.
180
- When converting an existing explicit declaration, use the shorthand only if its
181
- source already has that ID; changing the source ID creates a different resource.
182
- No top-level `properties` field is added to the database intent.
187
+ `schema` and `datasources` are mutually exclusive. A database declaration must
188
+ include at least one data source or at least one view. A linked-only database
189
+ may omit `datasources`, or use `datasources: {}`, only when `views` is nonempty;
190
+ `{}`, `{ datasources: {} }`, and `{ datasources: {}, views: [] }` are invalid.
191
+ Page and teamspace child helpers accept the same forms through
192
+ `page.addDatabase("database-id", args)` and `teamspace.addDatabase("database-id", args)`.
193
+
194
+ Each `datasources` key is the source's name, and each `schema` key is the
195
+ property's name used for typed access, sync keys, and serialized properties.
196
+ Nested data-source configs and property configs do not accept `name`. The
197
+ top-level database `name` remains supported; in the single-source shorthand it
198
+ supplies both the database and data-source display names. In a multi-source
199
+ declaration, it names the database while each data-source name comes from its key.
200
+
201
+ All database, source, and property IDs remain explicit and must be globally unique.
202
+ No IDs are generated from keys or names. The build emits the existing `dataSources`
203
+ and `properties` arrays with exact IDs and names from those keys; authoring
204
+ `schema`, `datasources`, and database-level `dataSourceResourceId` fields do not
205
+ leak into the serialized database intent. The provisioning JSON envelope and
206
+ server API are unchanged. See [the build guide](docs/BUILD.md#declaring-notion-as-code-databases)
207
+ for complete single-, multi-source, and linked-only examples.
183
208
 
184
209
  Declare database views with `views` or `addView`, or use the top-level `view`
185
210
  function from `@notionhq/apps` (`notion.view` is also available). The standalone
@@ -196,7 +221,7 @@ view({
196
221
  databaseResourceId: issues.resourceId,
197
222
  resourceId: "issues-table",
198
223
  type: "table",
199
- dataSourceResourceId: issues.dataSource.resourceId,
224
+ dataSourceResourceId: issues.datasources.Issues.resourceId,
200
225
  properties: [{ property: "issue-title", visible: true }],
201
226
  sorts: [{ propertyId: "issue-title", direction: "ascending" }],
202
227
  });
package/dist/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export { teamspace } from "./notion-as-code/teamspace.js";
6
6
  export { view } from "./notion-as-code/view.js";
7
7
  export { sync } from "./sync.js";
8
8
  export { workflow } from "./workflow.js";
9
+ export type { WorkflowState, WorkflowStateValue } from "./workflow-state.js";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,68 +1,108 @@
1
1
  import type { Database } from "../database.js";
2
- import { type DataSourceDefinition, type NotionAsCodeIcon, type NotionAsCodeProperty, type Parent, type ResourceId } from "./intents.js";
2
+ import { type DatabaseIntent, type NotionAsCodeIcon, type NotionAsCodeSchema, type Parent, type ResourceId } from "./intents.js";
3
3
  import { type ChildPageArgs, type PageHandle } from "./page.js";
4
- import { type AppsSchemaForProperties } from "./schema.js";
4
+ import { type AppsSchemaForSchema } from "./schema.js";
5
5
  import type { ViewSchema } from "./views.js";
6
- /** Input for declaring a database and its optional data sources. */
7
- export type DatabaseArgs<DataSources extends readonly DataSourceDefinition[] = readonly DataSourceDefinition[]> = {
6
+ /** Reuse serialized database intent metadata, excluding identity, parent, and sources. */
7
+ type DatabaseMetadata = Omit<DatabaseIntent, "resourceId" | "parent" | "dataSources">;
8
+ type NonEmptyViewSchemas = readonly [ViewSchema, ...ViewSchema[]];
9
+ /** A keyed data-source declaration; the containing map key supplies the serialized source name. */
10
+ export type DataSourceArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = {
8
11
  resourceId: ResourceId;
9
- /** Omit to create a private top-level database in the Apps workspace. */
10
- parent?: Parent;
11
- dataSources?: DataSources;
12
- views?: readonly ViewSchema[];
12
+ name?: never;
13
+ schema: Schema;
13
14
  icon?: NotionAsCodeIcon;
14
- cover?: unknown;
15
- hideDataSourceTitle?: boolean;
16
- hideDatabaseTitleIfEmpty?: boolean;
17
- name?: string;
18
- description?: string;
19
15
  };
20
- /** Input for adding a database beneath an existing resource. */
21
- export type ChildDatabaseArgs<DataSources extends readonly DataSourceDefinition[] = readonly DataSourceDefinition[]> = Omit<DatabaseArgs<DataSources>, "parent">;
22
- /** Single-source shorthand; the source ID is `${resourceId}-source`. */
23
- export type SingleSourceDatabaseArgs<Properties extends readonly NotionAsCodeProperty[] = readonly NotionAsCodeProperty[]> = Omit<DatabaseArgs, "dataSources" | "name"> & {
16
+ /** Data sources keyed by the names used to access their handles. */
17
+ export type DataSourceMap = Record<string, DataSourceArgs>;
18
+ /**
19
+ * Single-source inputs require a name for both database and source. `datasources?: never`
20
+ * keeps this form exclusive even when callers pass a predeclared object.
21
+ */
22
+ type SingleSourceDatabaseOptions<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = Omit<DatabaseMetadata, "name"> & {
23
+ dataSourceResourceId: ResourceId;
24
24
  name: string;
25
- properties: Properties;
26
- dataSources?: never;
25
+ schema: Schema;
26
+ datasources?: never;
27
27
  };
28
- export type ChildSingleSourceDatabaseArgs<Properties extends readonly NotionAsCodeProperty[] = readonly NotionAsCodeProperty[]> = Omit<SingleSourceDatabaseArgs<Properties>, "parent">;
29
- /** Resolves one data source ID to the properties declared for it. */
30
- type DataSourcePropertiesForResourceId<DataSources extends readonly DataSourceDefinition[], ResourceId extends DataSources[number]["resourceId"]> = Extract<DataSources[number], {
31
- resourceId: ResourceId;
32
- }> extends DataSourceDefinition<infer Properties> ? Properties : never;
33
- /** Handle for a data source and the Apps database it backs. */
34
- export type DataSourceHandle<Properties extends readonly NotionAsCodeProperty[] = readonly NotionAsCodeProperty[]> = {
28
+ /** Top-level single-source inputs may choose a parent; page.addDatabase/teamspace.addDatabase bind it instead. */
29
+ export type SingleSourceDatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = SingleSourceDatabaseOptions<Schema> & {
30
+ parent?: Parent;
31
+ };
32
+ /**
33
+ * Multi-source inputs preserve source-map keys. The NoInfer guard makes the
34
+ * emptiness check inspect the inferred map instead of widening it to the broad
35
+ * DataSourceMap constraint.
36
+ */
37
+ type MultiSourceDatabaseOptions<DataSources extends DataSourceMap = DataSourceMap> = DatabaseMetadata & {
38
+ datasources: DataSources;
39
+ dataSourceResourceId?: never;
40
+ schema?: never;
41
+ } & (keyof NoInfer<DataSources> extends never ? {
42
+ views: NonEmptyViewSchemas;
43
+ } : {
44
+ views?: readonly ViewSchema[];
45
+ });
46
+ /** Top-level multi-source inputs may choose a parent; page.addDatabase/teamspace.addDatabase bind it instead. */
47
+ export type MultiSourceDatabaseArgs<DataSources extends DataSourceMap = DataSourceMap> = MultiSourceDatabaseOptions<DataSources> & {
48
+ parent?: Parent;
49
+ };
50
+ /** Linked-only databases use a nonempty typed view tuple and no authored source map. */
51
+ type ViewOnlyDatabaseOptions = DatabaseMetadata & {
52
+ datasources?: never;
53
+ dataSourceResourceId?: never;
54
+ schema?: never;
55
+ views: NonEmptyViewSchemas;
56
+ };
57
+ type ViewOnlyDatabaseArgs = ViewOnlyDatabaseOptions & {
58
+ parent?: Parent;
59
+ };
60
+ /** Remove parent because page.addDatabase/teamspace.addDatabase supplies it. */
61
+ export type ChildSingleSourceDatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = Omit<SingleSourceDatabaseArgs<Schema>, "parent">;
62
+ /** Remove parent because page.addDatabase/teamspace.addDatabase supplies it. */
63
+ export type ChildMultiSourceDatabaseArgs<DataSources extends DataSourceMap = DataSourceMap> = Omit<MultiSourceDatabaseArgs<DataSources>, "parent">;
64
+ /** Input for declaring a database and its data sources. */
65
+ export type DatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema, DataSources extends DataSourceMap = DataSourceMap> = SingleSourceDatabaseArgs<Schema> | MultiSourceDatabaseArgs<DataSources> | ViewOnlyDatabaseArgs;
66
+ /**
67
+ * Child inputs omit parent from each union member separately. `page.addDatabase`
68
+ * and `teamspace.addDatabase` use this shape for their shared child factory.
69
+ */
70
+ export type ChildDatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema, DataSources extends DataSourceMap = DataSourceMap> = ChildSingleSourceDatabaseArgs<Schema> | ChildMultiSourceDatabaseArgs<DataSources> | Omit<ViewOnlyDatabaseArgs, "parent">;
71
+ /** A source handle retains its keyed authoring schema for sync inference. */
72
+ export type DataSourceHandle<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = {
35
73
  readonly resourceId: string;
36
- readonly schema: Properties;
37
- readonly database: Database<AppsSchemaForProperties<Properties>>;
74
+ readonly schema: Schema;
75
+ readonly database: Database<AppsSchemaForSchema<Schema>>;
38
76
  addPage: (args: ChildPageArgs) => PageHandle;
39
77
  };
40
- /** Handle for a database with data sources indexed by resource ID. */
41
- export type DatabaseHandle<DataSources extends readonly DataSourceDefinition[] = readonly DataSourceDefinition[]> = {
78
+ type DatabaseHandleBase = {
42
79
  readonly resourceId: string;
43
- readonly dataSources: {
44
- readonly [ResourceId in DataSources[number]["resourceId"]]: DataSourceHandle<DataSourcePropertiesForResourceId<DataSources, ResourceId>>;
45
- };
46
80
  addView: (view: ViewSchema) => void;
47
81
  };
48
- /** A database whose sole data source is available without an ID lookup. */
49
- export type SingleSourceDatabaseHandle<Properties extends readonly NotionAsCodeProperty[] = readonly NotionAsCodeProperty[]> = DatabaseHandle<readonly DataSourceDefinition<Properties>[]> & {
50
- readonly dataSource: DataSourceHandle<Properties>;
82
+ /** Map each authoring source key to a handle backed by that source's own schema. */
83
+ export type DatabaseHandle<DataSources extends DataSourceMap = DataSourceMap> = DatabaseHandleBase & {
84
+ readonly datasources: {
85
+ readonly [DataSourceName in keyof DataSources]: DataSourceHandle<DataSources[DataSourceName]["schema"]>;
86
+ };
87
+ };
88
+ /** A database whose sole data source is available without a key lookup. */
89
+ export type SingleSourceDatabaseHandle<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = DatabaseHandleBase & {
90
+ readonly dataSource: DataSourceHandle<Schema>;
51
91
  };
92
+ /**
93
+ * Overloaded callable used by page.addDatabase/teamspace.addDatabase. Each form
94
+ * returns its matching handle while preserving literal source and schema inference.
95
+ */
52
96
  export type ChildDatabaseFactory = {
53
- <const Properties extends readonly NotionAsCodeProperty[]>(args: ChildSingleSourceDatabaseArgs<Properties>): SingleSourceDatabaseHandle<Properties>;
54
- <const DataSources extends readonly DataSourceDefinition[]>(args: ChildDatabaseArgs<DataSources> & {
55
- properties?: never;
56
- }): DatabaseHandle<DataSources>;
97
+ <const Schema extends NotionAsCodeSchema>(databaseResourceId: ResourceId, args: ChildSingleSourceDatabaseArgs<Schema>): SingleSourceDatabaseHandle<Schema>;
98
+ <const DataSources extends DataSourceMap>(databaseResourceId: ResourceId, args: ChildMultiSourceDatabaseArgs<DataSources>): DatabaseHandle<DataSources>;
99
+ (databaseResourceId: ResourceId, args: Omit<ViewOnlyDatabaseArgs, "parent">): DatabaseHandle<{}>;
57
100
  };
58
- /** Declare a database, defaulting to a private top-level database in the Apps workspace. */
59
- export declare function database<const Properties extends readonly NotionAsCodeProperty[]>(args: SingleSourceDatabaseArgs<Properties>): SingleSourceDatabaseHandle<Properties>;
60
- export declare function database<const DataSources extends readonly DataSourceDefinition[]>(args: DatabaseArgs<DataSources> & {
61
- properties?: never;
62
- }): DatabaseHandle<DataSources>;
63
- /** Bind both database declaration forms to an existing parent. */
101
+ /** Declare a database, defaulting to the Apps workspace. */
102
+ export declare function database<const Schema extends NotionAsCodeSchema>(databaseResourceId: ResourceId, args: SingleSourceDatabaseArgs<Schema>): SingleSourceDatabaseHandle<Schema>;
103
+ export declare function database<const DataSources extends DataSourceMap>(databaseResourceId: ResourceId, args: MultiSourceDatabaseArgs<DataSources>): DatabaseHandle<DataSources>;
104
+ export declare function database(databaseResourceId: ResourceId, args: ViewOnlyDatabaseArgs): DatabaseHandle<{}>;
105
+ /** Bind a parent for page.addDatabase/teamspace.addDatabase. */
64
106
  export declare function createChildDatabase(parent: Parent): ChildDatabaseFactory;
65
- /** Record a database declaration and create handles for each of its data sources. */
66
- export declare function createDatabase(args: DatabaseArgs, parent: Parent): DatabaseHandle;
67
107
  export {};
68
108
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAEN,KAAK,oBAAoB,EA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page.js";
5
5
  import { recordIntent } from "./recorder.js";
6
6
  import { assertParent, assertUserResourceId } from "./resource.js";
7
7
  import { createAppsDatabase } from "./schema.js";
8
- function database(args) {
9
- if (args.parent) {
10
- assertParent(args.parent);
8
+ function database(databaseResourceId, args) {
9
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
10
+ throw new Error("Notion-as-Code database arguments must be an object");
11
11
  }
12
- const parent = args.parent ?? {
12
+ const parentValue = args.parent;
13
+ if (parentValue !== void 0) {
14
+ assertParent(parentValue);
15
+ }
16
+ const parent = parentValue ?? {
13
17
  type: "resourceId",
14
18
  resourceId: APPS_WORKSPACE_RESOURCE_ID
15
19
  };
16
- if ("properties" in args) {
17
- if (args.dataSources !== void 0) {
18
- throw new Error("Specify either properties or dataSources, not both");
19
- }
20
- const { properties, ...databaseArgs } = args;
20
+ return buildDatabaseHandle(databaseResourceId, args, parent);
21
+ }
22
+ function createChildDatabase(parent) {
23
+ assertParent(parent);
24
+ function addDatabase(databaseResourceId, args) {
25
+ return buildDatabaseHandle(databaseResourceId, args, parent);
26
+ }
27
+ return addDatabase;
28
+ }
29
+ function buildDatabaseHandle(databaseResourceId, args, parent) {
30
+ if (typeof args !== "object" || args === null || Array.isArray(args)) {
31
+ throw new Error("Notion-as-Code database arguments must be an object");
32
+ }
33
+ if (typeof databaseResourceId !== "string") {
34
+ throw new Error("Notion-as-Code database resourceId must be a string");
35
+ }
36
+ assertUserResourceId(databaseResourceId);
37
+ const hasSchema = Object.prototype.hasOwnProperty.call(args, "schema");
38
+ const hasDataSources = Object.prototype.hasOwnProperty.call(args, "datasources");
39
+ if (hasSchema && hasDataSources) {
40
+ throw new Error("Specify either schema or datasources, not both");
41
+ }
42
+ if (args.schema !== void 0) {
21
43
  const source = {
22
- resourceId: `${args.resourceId}-source`,
44
+ resourceId: args.dataSourceResourceId,
23
45
  name: args.name,
24
- properties
46
+ properties: normalizeProperties(args.schema)
47
+ };
48
+ const handle = recordDatabase(databaseResourceId, args, parent, [
49
+ { key: "dataSource", schema: args.schema, definition: source }
50
+ ]);
51
+ const dataSource = handle.datasources.dataSource;
52
+ if (dataSource === void 0) {
53
+ throw new Error(`Database "${databaseResourceId}" is missing its data source`);
54
+ }
55
+ return {
56
+ resourceId: databaseResourceId,
57
+ dataSource,
58
+ addView: handle.addView
25
59
  };
26
- const handle = createDatabase({ ...databaseArgs, dataSources: [source] }, parent);
27
- const dataSource = handle.dataSources[source.resourceId];
28
- if (!dataSource) {
29
- throw new Error(`Missing data source "${source.resourceId}"`);
60
+ }
61
+ if (args.datasources !== void 0) {
62
+ if (typeof args.datasources !== "object" || args.datasources === null || Array.isArray(args.datasources)) {
63
+ throw new Error("Notion-as-Code datasources must be an object");
30
64
  }
31
- return { ...handle, dataSource };
65
+ const sourceEntries = Object.entries(args.datasources).map(
66
+ ([key, sourceArgs]) => normalizeDataSource(key, sourceArgs)
67
+ );
68
+ return recordDatabase(databaseResourceId, args, parent, sourceEntries);
32
69
  }
33
- return createDatabase(args, parent);
70
+ return recordDatabase(databaseResourceId, args, parent, []);
34
71
  }
35
- function createChildDatabase(parent) {
36
- function addDatabase(args) {
37
- if ("properties" in args) {
38
- return database({ ...args, parent });
72
+ function normalizeDatabaseMetadata(args) {
73
+ const {
74
+ parent: _parent,
75
+ schema: _schema,
76
+ datasources: _datasources,
77
+ dataSourceResourceId: _dataSourceResourceId,
78
+ ...metadata
79
+ } = args;
80
+ return metadata;
81
+ }
82
+ function normalizeDataSource(key, sourceArgs) {
83
+ if (typeof sourceArgs !== "object" || sourceArgs === null || Array.isArray(sourceArgs)) {
84
+ throw new Error(`Data source "${key}" must be an object`);
85
+ }
86
+ const { schema, ...sourceMetadata } = sourceArgs;
87
+ return {
88
+ key,
89
+ schema,
90
+ definition: {
91
+ ...sourceMetadata,
92
+ name: key,
93
+ properties: normalizeProperties(schema)
39
94
  }
40
- return database({ ...args, parent });
95
+ };
96
+ }
97
+ function normalizeProperties(schema) {
98
+ if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
99
+ throw new Error("Notion-as-Code schema must be an object");
41
100
  }
42
- return addDatabase;
101
+ const properties = [];
102
+ for (const [key, propertyConfig] of Object.entries(schema)) {
103
+ if (typeof propertyConfig !== "object" || propertyConfig === null || Array.isArray(propertyConfig)) {
104
+ throw new Error(`Property "${key}" must be an object`);
105
+ }
106
+ if (typeof propertyConfig.resourceId !== "string") {
107
+ throw new Error(`Property "${key}" must specify a resourceId`);
108
+ }
109
+ properties.push({
110
+ ...propertyConfig,
111
+ name: key
112
+ });
113
+ }
114
+ return properties;
43
115
  }
44
- function createDatabase(args, parent) {
45
- assertUserResourceId(args.resourceId);
46
- const dataSources = args.dataSources ?? [];
116
+ function assertSourceOrView(sourceEntries, views) {
117
+ if (views !== void 0 && !Array.isArray(views)) {
118
+ throw new Error("Notion-as-Code database views must be an array");
119
+ }
120
+ if (sourceEntries.length === 0 && (!Array.isArray(views) || views.length === 0)) {
121
+ throw new Error("Notion-as-Code database must define a data source or view");
122
+ }
123
+ }
124
+ function recordDatabase(databaseResourceId, args, parent, sourceEntries) {
125
+ const metadata = normalizeDatabaseMetadata(args);
126
+ assertSourceOrView(sourceEntries, metadata.views);
127
+ const intent = {
128
+ ...metadata,
129
+ resourceId: databaseResourceId,
130
+ parent,
131
+ dataSources: sourceEntries.map(({ definition }) => definition)
132
+ };
133
+ return createDatabase(intent, sourceEntries);
134
+ }
135
+ function createDatabase(intent, sourceEntries) {
136
+ assertUserResourceId(intent.resourceId);
47
137
  const dataSourceIds = /* @__PURE__ */ new Set();
48
- const handles = {};
49
- for (const dataSource of dataSources) {
50
- assertUserResourceId(dataSource.resourceId);
51
- if (dataSourceIds.has(dataSource.resourceId)) {
138
+ const handles = /* @__PURE__ */ Object.create(null);
139
+ for (const { key, schema, definition } of sourceEntries) {
140
+ if (typeof definition.resourceId !== "string") {
141
+ throw new Error(`Data source "${key}" must specify a resourceId`);
142
+ }
143
+ assertUserResourceId(definition.resourceId);
144
+ if (dataSourceIds.has(definition.resourceId)) {
52
145
  throw new Error(
53
- `Database "${args.resourceId}" has duplicate data source "${dataSource.resourceId}"`
146
+ `Database "${intent.resourceId}" has duplicate data source "${definition.resourceId}"`
54
147
  );
55
148
  }
56
- dataSourceIds.add(dataSource.resourceId);
57
- handles[dataSource.resourceId] = createDataSourceHandle(dataSource);
149
+ dataSourceIds.add(definition.resourceId);
150
+ handles[key] = createDataSourceHandle(definition, schema);
58
151
  }
59
- recordIntent({
60
- type: "database",
61
- ...args,
62
- parent,
63
- dataSources: [...dataSources]
64
- });
152
+ recordIntent({ ...intent, type: "database" });
65
153
  return {
66
- resourceId: args.resourceId,
67
- dataSources: handles,
154
+ resourceId: intent.resourceId,
155
+ datasources: handles,
68
156
  addView(view) {
69
- recordIntent({ type: "view", databaseResourceId: args.resourceId, view });
157
+ recordIntent({ type: "view", databaseResourceId: intent.resourceId, view });
70
158
  }
71
159
  };
72
160
  }
73
- function createDataSourceHandle(dataSource) {
161
+ function createDataSourceHandle(dataSource, schema) {
74
162
  const propertyResourceIds = /* @__PURE__ */ new Set();
75
163
  const propertyNames = /* @__PURE__ */ new Set();
76
164
  for (const property of dataSource.properties) {
@@ -90,7 +178,7 @@ function createDataSourceHandle(dataSource) {
90
178
  }
91
179
  return {
92
180
  resourceId: dataSource.resourceId,
93
- schema: dataSource.properties,
181
+ schema,
94
182
  database: createAppsDatabase(dataSource.resourceId, dataSource),
95
183
  addPage(pageArgs) {
96
184
  return createPage(pageArgs, { type: "resourceId", resourceId: dataSource.resourceId });
@@ -99,6 +187,5 @@ function createDataSourceHandle(dataSource) {
99
187
  }
100
188
  export {
101
189
  createChildDatabase,
102
- createDatabase,
103
190
  database
104
191
  };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=database.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.test.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/database.test.ts"],"names":[],"mappings":""}
@@ -1,7 +1,7 @@
1
1
  export { APPS_RESERVED_RESOURCE_ID_PREFIX, APPS_WORKSPACE_RESOURCE_ID } from "./intents.js";
2
- export type { DataSourceDefinition, NotionAsCodeProperty, Parent } from "./intents.js";
2
+ export type { DatabaseIntent, DataSourceDefinition, NotionAsCodeIcon, NotionAsCodeProperty, NotionAsCodePropertyConfig, NotionAsCodeSchema, NotionAsCodeSelectOption, NotionAsCodeStatusOption, Parent, ResourceId, } from "./intents.js";
3
3
  export type { CustomAgentArgs, CustomAgentHandle } from "./custom-agent.js";
4
- export type { ChildDatabaseArgs, ChildDatabaseFactory, ChildSingleSourceDatabaseArgs, DataSourceHandle, DatabaseArgs, DatabaseHandle, SingleSourceDatabaseArgs, SingleSourceDatabaseHandle, } from "./database.js";
4
+ export type { ChildDatabaseArgs, ChildDatabaseFactory, ChildMultiSourceDatabaseArgs, ChildSingleSourceDatabaseArgs, DataSourceArgs, DataSourceHandle, DataSourceMap, DatabaseArgs, DatabaseHandle, MultiSourceDatabaseArgs, SingleSourceDatabaseArgs, SingleSourceDatabaseHandle, } from "./database.js";
5
5
  export type { ChildPageArgs, PageArgs, PageHandle } from "./page.js";
6
6
  export type { TeamspaceArgs, TeamspaceHandle } from "./teamspace.js";
7
7
  export type { ViewArgs, ViewHandle } from "./view.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACvF,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,YAAY,EACX,iBAAiB,EACjB,oBAAoB,EACpB,6BAA6B,EAC7B,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,0BAA0B,GAC1B,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,YAAY,EACX,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,yBAAyB,EACzB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,4BAA4B,EAC5B,iCAAiC,EACjC,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,+BAA+B,EAC/B,qBAAqB,EACrB,sCAAsC,EACtC,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AAEpB,wEAAwE;AACxE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;CAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,YAAY,EACX,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAA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