@instantdb/platform 0.22.95-experimental.surgical.20386947966.1 → 0.22.96-experimental.add-posthog-frontend.20386914944.1
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/.turbo/turbo-build.log +9 -9
- package/dist/commonjs/api.d.ts.map +1 -1
- package/dist/commonjs/api.js +1 -1
- package/dist/commonjs/api.js.map +1 -1
- package/dist/commonjs/index.d.ts +0 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -9
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +14 -12
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/esm/api.d.ts.map +1 -1
- package/dist/esm/api.js +1 -1
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +15 -13
- package/dist/esm/schema.js.map +1 -1
- package/dist/standalone/index.js +1130 -1217
- package/dist/standalone/index.umd.cjs +25 -32
- package/package.json +3 -3
- package/src/api.ts +2 -0
- package/src/index.ts +0 -10
- package/src/schema.ts +24 -16
- package/dist/commonjs/schemaCodegen.d.ts +0 -37
- package/dist/commonjs/schemaCodegen.d.ts.map +0 -1
- package/dist/commonjs/schemaCodegen.js +0 -112
- package/dist/commonjs/schemaCodegen.js.map +0 -1
- package/dist/esm/schemaCodegen.d.ts +0 -37
- package/dist/esm/schemaCodegen.d.ts.map +0 -1
- package/dist/esm/schemaCodegen.js +0 -103
- package/dist/esm/schemaCodegen.js.map +0 -1
- package/src/schemaCodegen.ts +0 -183
package/src/schemaCodegen.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AttrsDefs,
|
|
3
|
-
DataAttrDef,
|
|
4
|
-
LinkDef,
|
|
5
|
-
LinksDef,
|
|
6
|
-
} from '@instantdb/core';
|
|
7
|
-
import { indentLines, joinWithTrailingSep, sortedEntries } from './util.ts';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_INDENT = 2;
|
|
10
|
-
|
|
11
|
-
type AnyLink = LinkDef<any, any, any, any, any, any, any>;
|
|
12
|
-
|
|
13
|
-
type KeyFormatOptions = {
|
|
14
|
-
alwaysQuote?: boolean;
|
|
15
|
-
quote?: '"' | "'";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type EntityRenderOptions = {
|
|
19
|
-
indent?: number;
|
|
20
|
-
typeParamsByAttr?: Record<string, string | null | undefined>;
|
|
21
|
-
keyOptions?: KeyFormatOptions;
|
|
22
|
-
trailingComma?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type LinkRenderOptions = {
|
|
26
|
-
indent?: number;
|
|
27
|
-
keyOptions?: KeyFormatOptions;
|
|
28
|
-
stringQuote?: '"' | "'";
|
|
29
|
-
style?: 'js' | 'json';
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type LinksObjectOptions = {
|
|
33
|
-
indent?: number;
|
|
34
|
-
newlineForEmpty?: boolean;
|
|
35
|
-
keyOptions?: KeyFormatOptions;
|
|
36
|
-
stringQuote?: '"' | "'";
|
|
37
|
-
style?: 'js' | 'json';
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export function formatKey(name: string, options: KeyFormatOptions = {}) {
|
|
41
|
-
const quote = options.quote ?? "'";
|
|
42
|
-
if (!options.alwaysQuote && isValidIdentifier(name)) {
|
|
43
|
-
return name;
|
|
44
|
-
}
|
|
45
|
-
return `${quote}${name}${quote}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function renderAttrCall(
|
|
49
|
-
attr: DataAttrDef<string, boolean, boolean>,
|
|
50
|
-
typeParams?: string | null,
|
|
51
|
-
) {
|
|
52
|
-
const type =
|
|
53
|
-
(attr.metadata?.derivedType as any)?.type || attr.valueType || 'any';
|
|
54
|
-
const unique = attr.config.unique ? '.unique()' : '';
|
|
55
|
-
const index = attr.config.indexed ? '.indexed()' : '';
|
|
56
|
-
const required = attr.required ? '' : '.optional()';
|
|
57
|
-
return `i.${type}${typeParams ?? ''}()${unique}${index}${required}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function renderAttrProperty(
|
|
61
|
-
name: string,
|
|
62
|
-
attr: DataAttrDef<string, boolean, boolean>,
|
|
63
|
-
options: { typeParams?: string | null; keyOptions?: KeyFormatOptions } = {},
|
|
64
|
-
) {
|
|
65
|
-
return `${formatKey(name, options.keyOptions)}: ${renderAttrCall(
|
|
66
|
-
attr,
|
|
67
|
-
options.typeParams,
|
|
68
|
-
)}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function renderEntityProperty(
|
|
72
|
-
name: string,
|
|
73
|
-
attrs: AttrsDefs,
|
|
74
|
-
options: EntityRenderOptions = {},
|
|
75
|
-
) {
|
|
76
|
-
const indent = options.indent ?? DEFAULT_INDENT;
|
|
77
|
-
const keyOptions = options.keyOptions;
|
|
78
|
-
const attrBlock = sortedEntries(attrs)
|
|
79
|
-
.map(([attrName, attrDef]) =>
|
|
80
|
-
renderAttrProperty(attrName, attrDef, {
|
|
81
|
-
typeParams: options.typeParamsByAttr?.[attrName] ?? null,
|
|
82
|
-
keyOptions,
|
|
83
|
-
}),
|
|
84
|
-
)
|
|
85
|
-
.filter(Boolean);
|
|
86
|
-
const attrBlockText = options.trailingComma
|
|
87
|
-
? joinWithTrailingSep(attrBlock, ',\n', ',')
|
|
88
|
-
: attrBlock.join(',\n');
|
|
89
|
-
const inner = attrBlockText.length
|
|
90
|
-
? `\n${indentLines(attrBlockText, indent)}\n`
|
|
91
|
-
: '';
|
|
92
|
-
return `${formatKey(name, keyOptions)}: i.entity({${inner}})`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function renderLinkValue(
|
|
96
|
-
link: AnyLink,
|
|
97
|
-
options: LinkRenderOptions = {},
|
|
98
|
-
) {
|
|
99
|
-
const indent = options.indent ?? DEFAULT_INDENT;
|
|
100
|
-
const indentStr = ' '.repeat(indent);
|
|
101
|
-
const keyOptions = options.keyOptions;
|
|
102
|
-
const q = options.stringQuote ?? "'";
|
|
103
|
-
const style = options.style ?? 'js';
|
|
104
|
-
const forwardLines = [
|
|
105
|
-
`${formatKey('on', keyOptions)}: ${q}${link.forward.on}${q}`,
|
|
106
|
-
`${formatKey('has', keyOptions)}: ${q}${link.forward.has}${q}`,
|
|
107
|
-
`${formatKey('label', keyOptions)}: ${q}${link.forward.label}${q}`,
|
|
108
|
-
];
|
|
109
|
-
if (link.forward.required) {
|
|
110
|
-
forwardLines.push(`${formatKey('required', keyOptions)}: true`);
|
|
111
|
-
}
|
|
112
|
-
if (link.forward.onDelete) {
|
|
113
|
-
forwardLines.push(
|
|
114
|
-
`${formatKey('onDelete', keyOptions)}: ${q}${link.forward.onDelete}${q}`,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const reverseLines = [
|
|
119
|
-
`${formatKey('on', keyOptions)}: ${q}${link.reverse.on}${q}`,
|
|
120
|
-
`${formatKey('has', keyOptions)}: ${q}${link.reverse.has}${q}`,
|
|
121
|
-
`${formatKey('label', keyOptions)}: ${q}${link.reverse.label}${q}`,
|
|
122
|
-
];
|
|
123
|
-
if (link.reverse.onDelete) {
|
|
124
|
-
reverseLines.push(
|
|
125
|
-
`${formatKey('onDelete', keyOptions)}: ${q}${link.reverse.onDelete}${q}`,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const forwardBodyLines =
|
|
130
|
-
style === 'json' ? forwardLines : forwardLines.map((line) => `${line},`);
|
|
131
|
-
const reverseBodyLines =
|
|
132
|
-
style === 'json' ? reverseLines : reverseLines.map((line) => `${line},`);
|
|
133
|
-
|
|
134
|
-
return [
|
|
135
|
-
'{',
|
|
136
|
-
`${indentStr}${formatKey('forward', keyOptions)}: {`,
|
|
137
|
-
`${indentStr}${indentStr}${forwardBodyLines.join(
|
|
138
|
-
`${style === 'json' ? ',' : ''}\n${indentStr}${indentStr}`,
|
|
139
|
-
)}`,
|
|
140
|
-
`${indentStr}}${style === 'json' ? ',' : ','}`,
|
|
141
|
-
`${indentStr}${formatKey('reverse', keyOptions)}: {`,
|
|
142
|
-
`${indentStr}${indentStr}${reverseBodyLines.join(
|
|
143
|
-
`${style === 'json' ? ',' : ''}\n${indentStr}${indentStr}`,
|
|
144
|
-
)}`,
|
|
145
|
-
`${indentStr}}${style === 'json' ? '' : ','}`,
|
|
146
|
-
'}',
|
|
147
|
-
].join('\n');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function renderLinkProperty(
|
|
151
|
-
name: string,
|
|
152
|
-
link: AnyLink,
|
|
153
|
-
options: LinkRenderOptions = {},
|
|
154
|
-
) {
|
|
155
|
-
return `${formatKey(name, options.keyOptions)}: ${renderLinkValue(
|
|
156
|
-
link,
|
|
157
|
-
options,
|
|
158
|
-
)}`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function renderLinksObject(
|
|
162
|
-
links: LinksDef<any>,
|
|
163
|
-
options: LinksObjectOptions = {},
|
|
164
|
-
) {
|
|
165
|
-
const indent = options.indent ?? DEFAULT_INDENT;
|
|
166
|
-
const entries = sortedEntries(links).map(([name, link]) =>
|
|
167
|
-
renderLinkProperty(name, link, {
|
|
168
|
-
indent,
|
|
169
|
-
keyOptions: options.keyOptions,
|
|
170
|
-
stringQuote: options.stringQuote,
|
|
171
|
-
style: options.style,
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
if (!entries.length && !options.newlineForEmpty) {
|
|
175
|
-
return '{}';
|
|
176
|
-
}
|
|
177
|
-
const inner = entries.length ? indentLines(entries.join(',\n'), indent) : '';
|
|
178
|
-
return `{\n${inner}\n}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function isValidIdentifier(name: string) {
|
|
182
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
183
|
-
}
|