@sidekickdb/components 0.0.0 → 2.0.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 +20 -0
- package/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +92 -2
- package/app/App.css +38 -0
- package/app/App.tsx +63 -0
- package/app/index.css +18 -0
- package/app/main.tsx +10 -0
- package/dist/components/DialogContentPrimitive.d.ts +1 -0
- package/dist/components/DialogContentPrimitive.d.ts.map +1 -0
- package/dist/components/StyleMe.d.ts +15 -0
- package/dist/components/StyleMe.d.ts.map +1 -0
- package/dist/components/error-boundary.d.ts +17 -0
- package/dist/components/error-boundary.d.ts.map +1 -0
- package/dist/components/explorer/__tests__/edit-row-dialog.test.d.ts +2 -0
- package/dist/components/explorer/__tests__/edit-row-dialog.test.d.ts.map +1 -0
- package/dist/components/explorer/__tests__/format-value.test.d.ts +2 -0
- package/dist/components/explorer/__tests__/format-value.test.d.ts.map +1 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts +17 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts.map +1 -0
- package/dist/components/explorer/edit-row-dialog.d.ts +15 -0
- package/dist/components/explorer/edit-row-dialog.d.ts.map +1 -0
- package/dist/components/explorer/expandable-deleted-attr.d.ts +15 -0
- package/dist/components/explorer/expandable-deleted-attr.d.ts.map +1 -0
- package/dist/components/explorer/explorer-layout.d.ts +9 -0
- package/dist/components/explorer/explorer-layout.d.ts.map +1 -0
- package/dist/components/explorer/format-value.d.ts +2 -0
- package/dist/components/explorer/format-value.d.ts.map +1 -0
- package/dist/components/explorer/index.d.ts +128 -0
- package/dist/components/explorer/index.d.ts.map +1 -0
- package/dist/components/explorer/inner-explorer.d.ts +17 -0
- package/dist/components/explorer/inner-explorer.d.ts.map +1 -0
- package/dist/components/explorer/new-namespace-dialog.d.ts +10 -0
- package/dist/components/explorer/new-namespace-dialog.d.ts.map +1 -0
- package/dist/components/explorer/query-inspector.d.ts +11 -0
- package/dist/components/explorer/query-inspector.d.ts.map +1 -0
- package/dist/components/explorer/recently-deleted.d.ts +36 -0
- package/dist/components/explorer/recently-deleted.d.ts.map +1 -0
- package/dist/components/explorer/search-input.d.ts +9 -0
- package/dist/components/explorer/search-input.d.ts.map +1 -0
- package/dist/components/explorer/table-components.d.ts +16 -0
- package/dist/components/explorer/table-components.d.ts.map +1 -0
- package/dist/components/explorer/view-settings.d.ts +10 -0
- package/dist/components/explorer/view-settings.d.ts.map +1 -0
- package/dist/components/rosePineDawnTheme.d.ts +13 -0
- package/dist/components/rosePineDawnTheme.d.ts.map +1 -0
- package/dist/components/select.d.ts +16 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/toast.d.ts +4 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/ui.d.ts +349 -0
- package/dist/components/ui.d.ts.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/hooks/__tests__/explorer.test.d.ts +2 -0
- package/dist/hooks/__tests__/explorer.test.d.ts.map +1 -0
- package/dist/hooks/explorer.d.ts +33 -0
- package/dist/hooks/explorer.d.ts.map +1 -0
- package/dist/hooks/useAttrNotes.d.ts +10 -0
- package/dist/hooks/useAttrNotes.d.ts.map +1 -0
- package/dist/hooks/useClickOutside.d.ts +3 -0
- package/dist/hooks/useClickOutside.d.ts.map +1 -0
- package/dist/hooks/useColumnVisibility.d.ts +12 -0
- package/dist/hooks/useColumnVisibility.d.ts.map +1 -0
- package/dist/hooks/useEditBlobConstraints.d.ts +32 -0
- package/dist/hooks/useEditBlobConstraints.d.ts.map +1 -0
- package/dist/hooks/useExplorerHistory.d.ts +1 -0
- package/dist/hooks/useExplorerHistory.d.ts.map +1 -0
- package/dist/hooks/useIsOverflow.d.ts +6 -0
- package/dist/hooks/useIsOverflow.d.ts.map +1 -0
- package/dist/hooks/useLocalStorage.d.ts +2 -0
- package/dist/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/hooks/useMonacoJSONSchema.d.ts +3 -0
- package/dist/hooks/useMonacoJSONSchema.d.ts.map +1 -0
- package/dist/hooks/useStableDB.d.ts +7 -0
- package/dist/hooks/useStableDB.d.ts.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9751 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +241 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/indexingJobs.d.ts +24 -0
- package/dist/utils/indexingJobs.d.ts.map +1 -0
- package/dist/utils/parsePermsJSON.d.ts +11 -0
- package/dist/utils/parsePermsJSON.d.ts.map +1 -0
- package/dist/utils/renames.d.ts +3 -0
- package/dist/utils/renames.d.ts.map +1 -0
- package/dist/utils/tableWidthSize.d.ts +9 -0
- package/dist/utils/tableWidthSize.d.ts.map +1 -0
- package/index.html +13 -0
- package/package.json +106 -3
- package/src/components/DialogContentPrimitive.tsx +0 -0
- package/src/components/StyleMe.tsx +97 -0
- package/src/components/error-boundary.tsx +76 -0
- package/src/components/explorer/__tests__/edit-row-dialog.test.ts +31 -0
- package/src/components/explorer/__tests__/format-value.test.ts +9 -0
- package/src/components/explorer/edit-namespace-dialog.tsx +1890 -0
- package/src/components/explorer/edit-row-dialog.tsx +1367 -0
- package/src/components/explorer/expandable-deleted-attr.tsx +170 -0
- package/src/components/explorer/explorer-layout.tsx +196 -0
- package/src/components/explorer/format-value.ts +9 -0
- package/src/components/explorer/index.tsx +280 -0
- package/src/components/explorer/inner-explorer.tsx +1524 -0
- package/src/components/explorer/new-namespace-dialog.tsx +55 -0
- package/src/components/explorer/query-inspector.tsx +395 -0
- package/src/components/explorer/recently-deleted.tsx +349 -0
- package/src/components/explorer/search-input.tsx +358 -0
- package/src/components/explorer/table-components.tsx +416 -0
- package/src/components/explorer/view-settings.tsx +76 -0
- package/src/components/rosePineDawnTheme.ts +45 -0
- package/src/components/select.tsx +198 -0
- package/src/components/toast.tsx +18 -0
- package/src/components/ui.tsx +1740 -0
- package/src/config.ts +57 -0
- package/src/hooks/__tests__/explorer.test.ts +109 -0
- package/src/hooks/explorer.tsx +137 -0
- package/src/hooks/useAttrNotes.ts +27 -0
- package/src/hooks/useClickOutside.ts +23 -0
- package/src/hooks/useColumnVisibility.ts +39 -0
- package/src/hooks/useEditBlobConstraints.ts +185 -0
- package/src/hooks/useExplorerHistory.ts +0 -0
- package/src/hooks/useIsOverflow.ts +24 -0
- package/src/hooks/useLocalStorage.ts +51 -0
- package/src/hooks/useMonacoJSONSchema.ts +41 -0
- package/src/hooks/useStableDB.ts +31 -0
- package/src/index.tsx +12 -0
- package/src/schema.ts +286 -0
- package/src/style.css +84 -0
- package/src/types.ts +359 -0
- package/src/utils/format.ts +13 -0
- package/src/utils/indexingJobs.ts +126 -0
- package/src/utils/parsePermsJSON.ts +35 -0
- package/src/utils/renames.ts +42 -0
- package/src/utils/tableWidthSize.ts +62 -0
- package/tailwind.config.cjs +48 -0
- package/tsconfig.json +22 -0
- package/vite-env.d.ts +1 -0
- package/vite.config.ts +50 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
export type RelationshipKinds =
|
|
2
|
+
| `many-many`
|
|
3
|
+
| 'one-one'
|
|
4
|
+
| 'one-many'
|
|
5
|
+
| 'many-one';
|
|
6
|
+
|
|
7
|
+
export const relationshipConstraints: Record<
|
|
8
|
+
RelationshipKinds,
|
|
9
|
+
{ cardinality: 'one' | 'many'; 'unique?': boolean }
|
|
10
|
+
> = {
|
|
11
|
+
/**
|
|
12
|
+
* users has_many tags
|
|
13
|
+
* tags has_many users
|
|
14
|
+
*/
|
|
15
|
+
'many-many': {
|
|
16
|
+
cardinality: 'many',
|
|
17
|
+
'unique?': false,
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* users has_one profile
|
|
21
|
+
* profiles has_one owner
|
|
22
|
+
*/
|
|
23
|
+
'one-one': {
|
|
24
|
+
cardinality: 'one',
|
|
25
|
+
'unique?': true,
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* users has_many posts
|
|
29
|
+
* posts has_one author
|
|
30
|
+
* [?users :users/posts ?posts]
|
|
31
|
+
* <---------------> unique!
|
|
32
|
+
*/
|
|
33
|
+
'many-one': {
|
|
34
|
+
cardinality: 'many',
|
|
35
|
+
'unique?': true,
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* posts has_one owner
|
|
40
|
+
* users has_many owned_posts
|
|
41
|
+
* [?posts :posts/user ?users]
|
|
42
|
+
* <---------------> unique!
|
|
43
|
+
*/
|
|
44
|
+
'one-many': {
|
|
45
|
+
cardinality: 'one',
|
|
46
|
+
'unique?': false,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const relationshipConstraintsInverse: Record<string, RelationshipKinds> =
|
|
51
|
+
Object.fromEntries(
|
|
52
|
+
Object.entries(relationshipConstraints).map(([k, v]) => [
|
|
53
|
+
`${v.cardinality}-${v['unique?']}`,
|
|
54
|
+
k as RelationshipKinds,
|
|
55
|
+
]),
|
|
56
|
+
);
|
|
57
|
+
// COPIED FROM www/lib/types!!!!!!!!!!! LOOK OUT
|
|
58
|
+
|
|
59
|
+
import { InstantIssue } from '@sidekickdb/core';
|
|
60
|
+
|
|
61
|
+
export type InstantApp = {
|
|
62
|
+
id: string;
|
|
63
|
+
pro: boolean;
|
|
64
|
+
title: string;
|
|
65
|
+
created_at: string;
|
|
66
|
+
admin_token: string;
|
|
67
|
+
rules: object | null;
|
|
68
|
+
user_app_role: 'owner' | 'admin' | 'collaborator';
|
|
69
|
+
members: InstantMember[] | null;
|
|
70
|
+
invites: InstantAppInvite | null;
|
|
71
|
+
magic_code_email_template: {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
email?: string;
|
|
75
|
+
body: string;
|
|
76
|
+
subject: string;
|
|
77
|
+
} | null;
|
|
78
|
+
org: { id: string; title: string } | null;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type InstantMember = {
|
|
82
|
+
id: string;
|
|
83
|
+
email: string;
|
|
84
|
+
role: 'admin' | 'collaborator';
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type InstantMemberInvite = {
|
|
88
|
+
id: string;
|
|
89
|
+
type: 'app' | 'org';
|
|
90
|
+
foreign_key: string;
|
|
91
|
+
title: string;
|
|
92
|
+
invitee_role: 'admin' | 'collaborator' | 'owner';
|
|
93
|
+
inviter_email: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type InstantAppInvite = {
|
|
97
|
+
id: string;
|
|
98
|
+
email: string;
|
|
99
|
+
status: 'pending' | 'accepted' | 'revoked';
|
|
100
|
+
role: 'admin' | 'collaborator';
|
|
101
|
+
sent_at: string;
|
|
102
|
+
expired: boolean;
|
|
103
|
+
}[];
|
|
104
|
+
|
|
105
|
+
export type InstantIndexingJobInvalidTriple = {
|
|
106
|
+
entity_id: string;
|
|
107
|
+
value: any;
|
|
108
|
+
json_type:
|
|
109
|
+
| 'string'
|
|
110
|
+
| 'number'
|
|
111
|
+
| 'boolean'
|
|
112
|
+
| 'null'
|
|
113
|
+
| 'object'
|
|
114
|
+
| 'array'
|
|
115
|
+
| 'date';
|
|
116
|
+
};
|
|
117
|
+
export type InstantIndexingJob = {
|
|
118
|
+
id: string;
|
|
119
|
+
app_id: string;
|
|
120
|
+
attr_id: string;
|
|
121
|
+
job_type:
|
|
122
|
+
| 'remove-data-type'
|
|
123
|
+
| 'check-data-type'
|
|
124
|
+
| 'index'
|
|
125
|
+
| 'remove-index'
|
|
126
|
+
| 'unique'
|
|
127
|
+
| 'remove-unique'
|
|
128
|
+
| 'required'
|
|
129
|
+
| 'remove-required'
|
|
130
|
+
| string;
|
|
131
|
+
job_status: 'completed' | 'waiting' | 'processing' | 'errored' | string;
|
|
132
|
+
job_stage: string;
|
|
133
|
+
work_estimate: number | null | undefined;
|
|
134
|
+
work_completed: number | null | undefined;
|
|
135
|
+
error:
|
|
136
|
+
| 'invalid-triple-error'
|
|
137
|
+
| 'invalid-attr-state-error'
|
|
138
|
+
| 'triple-not-unique-error'
|
|
139
|
+
| 'triple-too-large-error'
|
|
140
|
+
| 'missing-required-error'
|
|
141
|
+
| 'unexpected-error'
|
|
142
|
+
| string
|
|
143
|
+
| null
|
|
144
|
+
| undefined;
|
|
145
|
+
error_data?: {
|
|
146
|
+
count: number;
|
|
147
|
+
'entity-ids': number[];
|
|
148
|
+
};
|
|
149
|
+
checked_data_type: CheckedDataType | null | undefined;
|
|
150
|
+
created_at: string;
|
|
151
|
+
updated_at: string;
|
|
152
|
+
done_at: string;
|
|
153
|
+
invalid_unique_value: any;
|
|
154
|
+
invalid_triples_sample: InstantIndexingJobInvalidTriple[] | null | undefined;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export type OrgSummary = {
|
|
158
|
+
id: string;
|
|
159
|
+
title: string;
|
|
160
|
+
created_at: string;
|
|
161
|
+
role: 'owner' | 'admin' | 'collaborator' | 'app-member';
|
|
162
|
+
paid: boolean;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export type DashResponse = {
|
|
166
|
+
apps: InstantApp[];
|
|
167
|
+
invites?: InstantMemberInvite[];
|
|
168
|
+
user: {
|
|
169
|
+
email: string;
|
|
170
|
+
id: string;
|
|
171
|
+
};
|
|
172
|
+
orgs?: OrgSummary[];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type AppError = { body: { message: string } | undefined };
|
|
176
|
+
|
|
177
|
+
export type AuthorizedOriginService =
|
|
178
|
+
| 'generic'
|
|
179
|
+
| 'vercel'
|
|
180
|
+
| 'netlify'
|
|
181
|
+
| 'custom-scheme';
|
|
182
|
+
|
|
183
|
+
export type AuthorizedOrigin = {
|
|
184
|
+
id: string;
|
|
185
|
+
service: AuthorizedOriginService;
|
|
186
|
+
params: string[];
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type OAuthServiceProvider = {
|
|
190
|
+
id: string;
|
|
191
|
+
provider_name: string;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export type OAuthClient = {
|
|
195
|
+
id: string;
|
|
196
|
+
client_name: string;
|
|
197
|
+
client_id?: string;
|
|
198
|
+
provider_id: string;
|
|
199
|
+
authorization_endpoint?: string;
|
|
200
|
+
token_endpoint?: string;
|
|
201
|
+
discovery_endpoint?: string;
|
|
202
|
+
meta?: any;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export type AppsAuthResponse = {
|
|
206
|
+
authorized_redirect_origins: AuthorizedOrigin[] | null | undefined;
|
|
207
|
+
oauth_service_providers: OAuthServiceProvider[] | null | undefined;
|
|
208
|
+
oauth_clients: OAuthClient[] | null | undefined;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export type SubscriptionName = 'Free' | 'Pro';
|
|
212
|
+
|
|
213
|
+
export type AppsSubscriptionResponse = {
|
|
214
|
+
'subscription-name': SubscriptionName;
|
|
215
|
+
'total-app-bytes': number;
|
|
216
|
+
'total-storage-bytes': number;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export type DBIdent =
|
|
220
|
+
| [string, string, string]
|
|
221
|
+
| [string, string, string, boolean];
|
|
222
|
+
|
|
223
|
+
export type CheckedDataType = 'string' | 'number' | 'boolean' | 'date';
|
|
224
|
+
|
|
225
|
+
export interface DBAttr {
|
|
226
|
+
id: string;
|
|
227
|
+
'forward-identity': DBIdent;
|
|
228
|
+
'reverse-identity'?: DBIdent;
|
|
229
|
+
'index?': boolean;
|
|
230
|
+
'unique?': boolean;
|
|
231
|
+
'required?'?: boolean;
|
|
232
|
+
'primary?'?: boolean | undefined;
|
|
233
|
+
cardinality: 'one' | 'many';
|
|
234
|
+
'value-type': 'ref' | 'blob';
|
|
235
|
+
'inferred-types'?: Array<'string' | 'number' | 'boolean' | 'json'>;
|
|
236
|
+
catalog?: 'user' | 'system';
|
|
237
|
+
'checked-data-type'?: CheckedDataType;
|
|
238
|
+
'on-delete'?: 'cascade';
|
|
239
|
+
'on-delete-reverse'?: 'cascade';
|
|
240
|
+
metadata?: any;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface SchemaNamespace {
|
|
244
|
+
id: string;
|
|
245
|
+
name: string;
|
|
246
|
+
attrs: SchemaAttr[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface SchemaNamespaceMap {
|
|
250
|
+
id: string;
|
|
251
|
+
name: string;
|
|
252
|
+
attrs: Record<string, SchemaAttr>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface SchemaAttr {
|
|
256
|
+
id: string;
|
|
257
|
+
isForward: boolean;
|
|
258
|
+
namespace: string;
|
|
259
|
+
name: string;
|
|
260
|
+
type: 'ref' | 'blob';
|
|
261
|
+
isIndex: boolean;
|
|
262
|
+
isUniq: boolean;
|
|
263
|
+
isRequired?: boolean;
|
|
264
|
+
isPrimary?: boolean | undefined;
|
|
265
|
+
cardinality: 'one' | 'many';
|
|
266
|
+
linkConfig: {
|
|
267
|
+
forward: {
|
|
268
|
+
id: string;
|
|
269
|
+
namespace: string;
|
|
270
|
+
attr: string;
|
|
271
|
+
nsMap: SchemaNamespaceMap;
|
|
272
|
+
};
|
|
273
|
+
reverse:
|
|
274
|
+
| {
|
|
275
|
+
id: string;
|
|
276
|
+
namespace: string;
|
|
277
|
+
attr: string;
|
|
278
|
+
nsMap: SchemaNamespaceMap;
|
|
279
|
+
}
|
|
280
|
+
| undefined;
|
|
281
|
+
};
|
|
282
|
+
inferredTypes?: Array<'string' | 'number' | 'boolean' | 'json'>;
|
|
283
|
+
catalog?: 'user' | 'system';
|
|
284
|
+
checkedDataType?: CheckedDataType;
|
|
285
|
+
sortable: boolean;
|
|
286
|
+
onDelete?: 'cascade';
|
|
287
|
+
onDeleteReverse?: 'cascade';
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export type OAuthAppClientSecret = {
|
|
291
|
+
id: string;
|
|
292
|
+
clientId: string;
|
|
293
|
+
firstFour: string;
|
|
294
|
+
createdAt: string;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export type OAuthAppClient = {
|
|
298
|
+
clientId: string;
|
|
299
|
+
oauthAppId: string;
|
|
300
|
+
clientName: string;
|
|
301
|
+
authorizedRedirectUrls: string[] | null;
|
|
302
|
+
clientSecrets: OAuthAppClientSecret[] | null;
|
|
303
|
+
createdAt: string;
|
|
304
|
+
updatedAt: string;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
export type OAuthApp = {
|
|
308
|
+
id: string;
|
|
309
|
+
appId: string;
|
|
310
|
+
appName: string;
|
|
311
|
+
grantedScopes: string[];
|
|
312
|
+
isPublic: boolean;
|
|
313
|
+
supportEmail: string | null;
|
|
314
|
+
appHomePage: string | null;
|
|
315
|
+
appPrivacyPolicyLink: string | null;
|
|
316
|
+
appTosLink: string | null;
|
|
317
|
+
appLogo: string | null;
|
|
318
|
+
clients: OAuthAppClient[] | null;
|
|
319
|
+
createdAt: string;
|
|
320
|
+
updatedAt: string;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export type OAuthAppsResponse = {
|
|
324
|
+
apps: OAuthApp[];
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// re-export InstantIssue from the core library
|
|
328
|
+
export { type InstantIssue };
|
|
329
|
+
|
|
330
|
+
export type HasDefault<T> = {
|
|
331
|
+
user: T | undefined;
|
|
332
|
+
parsed: T;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export type WithOptional<O extends object> = Expand<
|
|
336
|
+
{
|
|
337
|
+
[K in keyof O as O[K] extends HasDefault<any> ? never : K]: O[K];
|
|
338
|
+
} & {
|
|
339
|
+
[K in keyof O as O[K] extends HasDefault<any>
|
|
340
|
+
? K
|
|
341
|
+
: never]?: O[K] extends HasDefault<infer B> ? B : never;
|
|
342
|
+
}
|
|
343
|
+
>;
|
|
344
|
+
|
|
345
|
+
export type BuiltIn = Date | Function | Error | RegExp;
|
|
346
|
+
|
|
347
|
+
export type Primitive = string | number | boolean | symbol | null | undefined;
|
|
348
|
+
|
|
349
|
+
export type Expand<T> = T extends BuiltIn | Primitive
|
|
350
|
+
? T
|
|
351
|
+
: T extends object
|
|
352
|
+
? T extends infer O
|
|
353
|
+
? { [K in keyof O]: Expand<O[K]> }
|
|
354
|
+
: never
|
|
355
|
+
: T;
|
|
356
|
+
|
|
357
|
+
export type WithDefaults<O extends Object> = Expand<{
|
|
358
|
+
[K in keyof O]: O[K] extends HasDefault<infer B> ? B : O[K];
|
|
359
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function formatBytes(bytes: number) {
|
|
2
|
+
const units = ['bytes', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb'];
|
|
3
|
+
let index = 0;
|
|
4
|
+
|
|
5
|
+
if (!bytes) return '0 bytes';
|
|
6
|
+
|
|
7
|
+
while (bytes >= 1024 && index < units.length - 1) {
|
|
8
|
+
bytes /= 1024;
|
|
9
|
+
index++;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return bytes.toFixed(2) + ' ' + units[index];
|
|
13
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import useSWRSubscription from 'swr/subscription';
|
|
2
|
+
import { CheckedDataType, InstantIndexingJob } from '@lib/types';
|
|
3
|
+
|
|
4
|
+
export async function createJob(
|
|
5
|
+
{
|
|
6
|
+
appId,
|
|
7
|
+
attrId,
|
|
8
|
+
jobType,
|
|
9
|
+
checkedDataType,
|
|
10
|
+
apiURI,
|
|
11
|
+
}: {
|
|
12
|
+
appId: string;
|
|
13
|
+
attrId: string;
|
|
14
|
+
jobType: InstantIndexingJob['job_type'];
|
|
15
|
+
checkedDataType?: CheckedDataType | null | undefined;
|
|
16
|
+
apiURI: string;
|
|
17
|
+
},
|
|
18
|
+
token: string,
|
|
19
|
+
): Promise<InstantIndexingJob> {
|
|
20
|
+
const res = await fetch(`${apiURI}/dash/apps/${appId}/indexing-jobs`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: {
|
|
23
|
+
authorization: `Bearer ${token}`,
|
|
24
|
+
'content-type': 'application/json',
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
'app-id': appId,
|
|
28
|
+
'attr-id': attrId,
|
|
29
|
+
'job-type': jobType,
|
|
30
|
+
'checked-data-type': checkedDataType,
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const json = await res.json();
|
|
35
|
+
return json.job;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function jobFetchLoop(
|
|
39
|
+
appId: string,
|
|
40
|
+
jobId: string,
|
|
41
|
+
token: string,
|
|
42
|
+
apiURI: string,
|
|
43
|
+
) {
|
|
44
|
+
let stopped = false;
|
|
45
|
+
let errored = false;
|
|
46
|
+
let waitMs = 20;
|
|
47
|
+
let lastBody: string | null = null;
|
|
48
|
+
|
|
49
|
+
const nextWaitMs = (body: string) => {
|
|
50
|
+
if (body !== lastBody) {
|
|
51
|
+
waitMs = 20;
|
|
52
|
+
lastBody = body;
|
|
53
|
+
return waitMs;
|
|
54
|
+
}
|
|
55
|
+
const ret = waitMs;
|
|
56
|
+
waitMs = Math.min(10000, waitMs * 2);
|
|
57
|
+
return ret;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const start = async (
|
|
61
|
+
cb: (data: InstantIndexingJob | null, error?: Error) => void,
|
|
62
|
+
) => {
|
|
63
|
+
while (!stopped && !errored) {
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(
|
|
66
|
+
`${apiURI}/dash/apps/${appId}/indexing-jobs/${jobId}`,
|
|
67
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
68
|
+
);
|
|
69
|
+
const body = await res.text();
|
|
70
|
+
const json = JSON.parse(body);
|
|
71
|
+
const job = json.job;
|
|
72
|
+
cb(job);
|
|
73
|
+
if (job.job_status !== 'processing' && job.job_status !== 'waiting') {
|
|
74
|
+
return job;
|
|
75
|
+
}
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, nextWaitMs(body)));
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error('Job polling error:', e);
|
|
79
|
+
errored = true;
|
|
80
|
+
cb(null, e as Error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
start: async (
|
|
87
|
+
cb: (data: InstantIndexingJob | null, error?: Error) => void,
|
|
88
|
+
): Promise<InstantIndexingJob> => {
|
|
89
|
+
return start(cb);
|
|
90
|
+
},
|
|
91
|
+
stop: () => {
|
|
92
|
+
stopped = true;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function useJobSubscription({
|
|
98
|
+
appId,
|
|
99
|
+
jobId,
|
|
100
|
+
token,
|
|
101
|
+
apiURI,
|
|
102
|
+
}: {
|
|
103
|
+
appId: string;
|
|
104
|
+
jobId: string;
|
|
105
|
+
token: string;
|
|
106
|
+
apiURI: string;
|
|
107
|
+
}) {
|
|
108
|
+
const { data, error } = useSWRSubscription(
|
|
109
|
+
['jobs', appId, jobId],
|
|
110
|
+
([_, appId, jobId], { next }) => {
|
|
111
|
+
const fetchLoop = jobFetchLoop(appId, jobId, token, apiURI);
|
|
112
|
+
fetchLoop.start((data, error) => next(error, data));
|
|
113
|
+
return () => fetchLoop.stop();
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return { data, error };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function jobIsErrored(job: InstantIndexingJob) {
|
|
121
|
+
return job.job_status === 'errored';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function jobIsCompleted(job: InstantIndexingJob) {
|
|
125
|
+
return job.job_status === 'completed' || job.job_status === 'errored';
|
|
126
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import JsonParser from 'json5';
|
|
2
|
+
|
|
3
|
+
// parse string as json5, returning the object,
|
|
4
|
+
// boolean values will be converted to strings
|
|
5
|
+
// return a normal json string
|
|
6
|
+
export const parsePermsJSON = (text: string): Result<string> => {
|
|
7
|
+
const parseResult = doTry(() =>
|
|
8
|
+
JsonParser.parse(text, (_key, value) => {
|
|
9
|
+
if (value === true) {
|
|
10
|
+
return 'true';
|
|
11
|
+
} else if (value === false) {
|
|
12
|
+
return 'false';
|
|
13
|
+
} else {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
return parseResult;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const doTry = <T>(fn: () => T): Result<T> => {
|
|
22
|
+
try {
|
|
23
|
+
const value = fn();
|
|
24
|
+
return { status: 'ok', value };
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return { status: 'error', error: error as Error };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type Result<T> =
|
|
31
|
+
| { status: 'ok'; value: T }
|
|
32
|
+
| {
|
|
33
|
+
status: 'error';
|
|
34
|
+
error: Error;
|
|
35
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SchemaNamespace } from '@lib/types';
|
|
2
|
+
|
|
3
|
+
export const createRenameNamespaceOps = (
|
|
4
|
+
newName: string,
|
|
5
|
+
namespace: SchemaNamespace,
|
|
6
|
+
namespaces: SchemaNamespace[],
|
|
7
|
+
) => {
|
|
8
|
+
const currentName = namespace.name;
|
|
9
|
+
const ops: any[] = [];
|
|
10
|
+
namespace.attrs.forEach((attr) => {
|
|
11
|
+
ops.push([
|
|
12
|
+
'update-attr',
|
|
13
|
+
{
|
|
14
|
+
id: attr.id,
|
|
15
|
+
'forward-identity': [
|
|
16
|
+
attr.linkConfig.forward.id,
|
|
17
|
+
newName,
|
|
18
|
+
attr.linkConfig.forward.attr,
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
namespaces.forEach((ns) => {
|
|
25
|
+
ns.attrs.forEach((attr) => {
|
|
26
|
+
if (attr.linkConfig.reverse?.namespace === currentName) {
|
|
27
|
+
ops.push([
|
|
28
|
+
'update-attr',
|
|
29
|
+
{
|
|
30
|
+
id: attr.id,
|
|
31
|
+
'reverse-identity': [
|
|
32
|
+
attr.linkConfig.reverse.id,
|
|
33
|
+
newName,
|
|
34
|
+
attr.linkConfig.reverse.attr,
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return ops;
|
|
42
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param columnId
|
|
4
|
+
* @param max set a maximum width to return
|
|
5
|
+
* @returns minimum width to display all column cells
|
|
6
|
+
* @throws Error if element with class ${columnId} not found
|
|
7
|
+
*/
|
|
8
|
+
export const getTableWidthSize = (columnId: string, max: number): number => {
|
|
9
|
+
const header = document.querySelector(`.th-${columnId}`);
|
|
10
|
+
if (!header) {
|
|
11
|
+
throw new Error(`Element with class th-${columnId} not found`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const tableCells = document.querySelectorAll(`span.td-${columnId}`);
|
|
15
|
+
|
|
16
|
+
// Create container for clones
|
|
17
|
+
const container = document.createElement('div');
|
|
18
|
+
container.style.position = 'absolute';
|
|
19
|
+
container.style.visibility = 'hidden';
|
|
20
|
+
container.style.top = '-9999px';
|
|
21
|
+
container.style.left = '-9999px';
|
|
22
|
+
container.style.width = 'auto';
|
|
23
|
+
container.style.whiteSpace = 'nowrap';
|
|
24
|
+
|
|
25
|
+
document.body.appendChild(container);
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
// Clone and measure header
|
|
29
|
+
const headerClone = header.cloneNode(true) as HTMLElement;
|
|
30
|
+
headerClone.style.display = 'inline-block';
|
|
31
|
+
headerClone.style.overflow = 'visible';
|
|
32
|
+
headerClone.style.width = 'auto';
|
|
33
|
+
headerClone.style.maxWidth = 'none';
|
|
34
|
+
headerClone.style.whiteSpace = 'nowrap';
|
|
35
|
+
container.appendChild(headerClone);
|
|
36
|
+
const headerWidth = headerClone.scrollWidth;
|
|
37
|
+
|
|
38
|
+
// Clone and measure each cell
|
|
39
|
+
const cellWidths = Array.from(tableCells).map((cell) => {
|
|
40
|
+
const cellClone = cell.cloneNode(true) as HTMLElement;
|
|
41
|
+
cellClone.style.display = 'inline-block';
|
|
42
|
+
cellClone.style.overflow = 'visible';
|
|
43
|
+
cellClone.style.width = 'auto';
|
|
44
|
+
cellClone.style.maxWidth = 'none';
|
|
45
|
+
cellClone.style.whiteSpace = 'nowrap';
|
|
46
|
+
container.appendChild(cellClone);
|
|
47
|
+
const width = cellClone.scrollWidth;
|
|
48
|
+
container.removeChild(cellClone);
|
|
49
|
+
return width;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const maxCellWidth = cellWidths.length > 0 ? Math.max(...cellWidths) : 0;
|
|
53
|
+
const maxWidth = Math.max(headerWidth, maxCellWidth);
|
|
54
|
+
|
|
55
|
+
// Add padding
|
|
56
|
+
const finalWidth = maxWidth + 12;
|
|
57
|
+
|
|
58
|
+
return Math.min(finalWidth, max);
|
|
59
|
+
} finally {
|
|
60
|
+
document.body.removeChild(container);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Tailwind v4 uses CSS-first configuration via style.css
|
|
2
|
+
// This config is kept for any remaining JS-based customizations
|
|
3
|
+
|
|
4
|
+
const sans = [
|
|
5
|
+
'ui-sans-serif',
|
|
6
|
+
'system-ui',
|
|
7
|
+
'-apple-system',
|
|
8
|
+
'BlinkMacSystemFont',
|
|
9
|
+
'Segoe UI',
|
|
10
|
+
'Roboto',
|
|
11
|
+
'Arial',
|
|
12
|
+
'Noto Sans',
|
|
13
|
+
'sans-serif',
|
|
14
|
+
'Apple Color Emoji',
|
|
15
|
+
'Segoe UI Emoji',
|
|
16
|
+
'Segoe UI Symbol',
|
|
17
|
+
'Noto Color Emoji',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
darkMode: 'class',
|
|
22
|
+
content: ['./src/**/*.{js,ts,jsx,tsx}'],
|
|
23
|
+
plugins: [],
|
|
24
|
+
theme: {
|
|
25
|
+
fontFamily: {
|
|
26
|
+
sans: ['Switzer', '"IBM Plex Sans"', ...sans],
|
|
27
|
+
mono: [
|
|
28
|
+
'ui-monospace',
|
|
29
|
+
'SFMono-Regular',
|
|
30
|
+
'Menlo',
|
|
31
|
+
'Monaco',
|
|
32
|
+
'Consolas',
|
|
33
|
+
'Liberation Mono',
|
|
34
|
+
'Courier New',
|
|
35
|
+
'monospace',
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
extend: {
|
|
39
|
+
colors: {
|
|
40
|
+
'secondary-border': '#ECECEC',
|
|
41
|
+
'secondary-fill': '#F2F2F2',
|
|
42
|
+
'off-black': '#333333',
|
|
43
|
+
surface: '#cacaca',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
future: { hoverOnlyWhenSupported: true },
|
|
48
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"exclude": ["node_modules", "dist"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"strict": true,
|
|
7
|
+
"outDir": "dist/tsc",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"rootDirs": ["src", "app"],
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"jsx": "react",
|
|
13
|
+
"checkJs": false,
|
|
14
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"baseUrl": ".",
|
|
17
|
+
"paths": {
|
|
18
|
+
"@lib/*": ["./src/*"]
|
|
19
|
+
},
|
|
20
|
+
"strictNullChecks": true
|
|
21
|
+
}
|
|
22
|
+
}
|
package/vite-env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|