@cogover/sdk 0.12.1 → 0.13.0
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.
- package/README.md +61 -12
- package/dist/crypto.js +93 -23
- package/dist/data.d.ts +160 -13
- package/dist/data.js +30 -14
- package/dist/index.d.ts +1 -1
- package/dist/internal/base64.js +19 -4
- package/dist/internal/record-reads.js +183 -0
- package/dist/internal/utf8.js +0 -36
- package/dist/records.d.ts +18 -0
- package/docs/en/api-reference/background-jobs.md +4 -1
- package/docs/en/api-reference/cryptography.md +8 -4
- package/docs/en/api-reference/overview.md +9 -2
- package/docs/en/api-reference/record-triggers.md +12 -0
- package/docs/en/api-reference/records.md +378 -33
- package/docs/en/api-reference/state-and-locks.md +3 -0
- package/docs/en/usage-guide.md +66 -1
- package/package.json +1 -1
- package/scripts/generate-workspace-types.mjs +19 -7
|
@@ -27,14 +27,23 @@ function extractObjects(documentValue) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function renderDeclaration(objectsValue) {
|
|
30
|
+
// SDK types used by the generated field types. The augmentation cannot see the module's own exports, so the
|
|
31
|
+
// declaration imports them; an unresolved name would silently become `any` under skipLibCheck.
|
|
32
|
+
const sdkTypes = new Set();
|
|
30
33
|
const objectLines = objectsValue
|
|
31
34
|
.filter((object) => typeof object?.slug === "string" && object.slug.length > 0)
|
|
32
35
|
.sort((left, right) => left.slug.localeCompare(right.slug))
|
|
33
|
-
.map(renderObject)
|
|
36
|
+
.map((object) => renderObject(object, sdkTypes))
|
|
34
37
|
.join("\n");
|
|
35
38
|
|
|
39
|
+
// Only the names in use are imported, so the file also compiles with noUnusedLocals.
|
|
40
|
+
const usedTypes = [...sdkTypes].sort();
|
|
41
|
+
const importLine = usedTypes.length === 0
|
|
42
|
+
? `import "@cogover/sdk";\n\n`
|
|
43
|
+
: `import type { ${usedTypes.join(", ")} } from "@cogover/sdk";\n\n`;
|
|
44
|
+
|
|
36
45
|
return `// Generated by @cogover/sdk. Do not edit manually.\n`
|
|
37
|
-
+
|
|
46
|
+
+ importLine
|
|
38
47
|
+ `declare module "@cogover/sdk" {\n`
|
|
39
48
|
+ ` interface WorkspaceObjects {\n`
|
|
40
49
|
+ objectLines
|
|
@@ -42,25 +51,25 @@ function renderDeclaration(objectsValue) {
|
|
|
42
51
|
+ `}\n`;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
|
-
function renderObject(object) {
|
|
54
|
+
function renderObject(object, sdkTypes) {
|
|
46
55
|
const fields = Array.isArray(object.fields) ? object.fields : [];
|
|
47
56
|
const fieldLines = fields
|
|
48
57
|
.filter((field) => typeof field?.slug === "string" && field.slug.length > 0)
|
|
49
58
|
.sort((left, right) => left.slug.localeCompare(right.slug))
|
|
50
|
-
.map((field) => ` ${property(field.slug)}: ${fieldType(field)};\n`)
|
|
59
|
+
.map((field) => ` ${property(field.slug)}: ${fieldType(field, sdkTypes)};\n`)
|
|
51
60
|
.join("");
|
|
52
61
|
return ` ${property(object.slug)}: {\n${fieldLines} };\n`;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
function fieldType(field) {
|
|
56
|
-
const baseType = baseFieldType(field);
|
|
64
|
+
function fieldType(field, sdkTypes) {
|
|
65
|
+
const baseType = baseFieldType(field, sdkTypes);
|
|
57
66
|
const nullableType = field.required === true ? baseType : `${baseType} | null`;
|
|
58
67
|
return field.multiple === true && !baseType.endsWith("[]")
|
|
59
68
|
? `readonly ${parenthesize(baseType)}[]${field.required === true ? "" : " | null"}`
|
|
60
69
|
: nullableType;
|
|
61
70
|
}
|
|
62
71
|
|
|
63
|
-
function baseFieldType(field) {
|
|
72
|
+
function baseFieldType(field, sdkTypes) {
|
|
64
73
|
switch (field.fieldType) {
|
|
65
74
|
case "short_text":
|
|
66
75
|
case "long_text":
|
|
@@ -88,11 +97,14 @@ function baseFieldType(field) {
|
|
|
88
97
|
case "cascading":
|
|
89
98
|
return `readonly ${parenthesize(optionUnion(field.options))}[]`;
|
|
90
99
|
case "url":
|
|
100
|
+
sdkTypes.add("UrlValue");
|
|
91
101
|
return "UrlValue";
|
|
92
102
|
case "file":
|
|
103
|
+
sdkTypes.add("FileValue");
|
|
93
104
|
return "FileValue";
|
|
94
105
|
case "lookup_normal":
|
|
95
106
|
case "reference": {
|
|
107
|
+
sdkTypes.add("RecordReference");
|
|
96
108
|
const objectSlug = referenceObjectSlug(field);
|
|
97
109
|
return objectSlug === null
|
|
98
110
|
? "RecordReference"
|