@drhomet/mithaq 0.0.0-stage → 0.1.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/LICENSE +22 -0
- package/LICENSES/payload.txt +22 -0
- package/LICENSES/ponytail.txt +21 -0
- package/dist/asas/actor.d.ts +96 -0
- package/dist/asas/actor.js +114 -0
- package/dist/asas/build.d.ts +231 -0
- package/dist/asas/build.js +787 -0
- package/dist/asas/cli/mithaq.d.ts +2 -0
- package/dist/asas/cli/mithaq.js +145 -0
- package/dist/asas/cli/upgrade.d.ts +20 -0
- package/dist/asas/cli/upgrade.js +147 -0
- package/dist/asas/http/fetch.d.ts +23 -0
- package/dist/asas/http/fetch.js +115 -0
- package/dist/asas/http/orpc.d.ts +43 -0
- package/dist/asas/http/orpc.js +135 -0
- package/dist/asas/runner/bulk.d.ts +20 -0
- package/dist/asas/runner/bulk.js +191 -0
- package/dist/asas/runner/errors.d.ts +60 -0
- package/dist/asas/runner/errors.js +59 -0
- package/dist/asas/runner/read.d.ts +68 -0
- package/dist/asas/runner/read.js +579 -0
- package/dist/asas/runner/runtime.d.ts +21 -0
- package/dist/asas/runner/runtime.js +8 -0
- package/dist/asas/runner/steps.d.ts +400 -0
- package/dist/asas/runner/steps.js +271 -0
- package/dist/asas/runner/tenant.d.ts +54 -0
- package/dist/asas/runner/tenant.js +213 -0
- package/dist/asas/runner/write.d.ts +444 -0
- package/dist/asas/runner/write.js +791 -0
- package/dist/auth/better-auth/access.d.ts +15 -0
- package/dist/auth/better-auth/access.js +71 -0
- package/dist/auth/better-auth/generate.d.ts +29 -0
- package/dist/auth/better-auth/generate.js +310 -0
- package/dist/auth/better-auth/index.d.ts +92 -0
- package/dist/auth/better-auth/index.js +81 -0
- package/dist/auth/better-auth/tenant.d.ts +18 -0
- package/dist/auth/better-auth/tenant.js +26 -0
- package/dist/auth/local/index.d.ts +285 -0
- package/dist/auth/local/index.js +736 -0
- package/dist/base/decimal.d.ts +9 -0
- package/dist/base/decimal.js +16 -0
- package/dist/base/fields.d.ts +123 -0
- package/dist/base/fields.js +51 -0
- package/dist/base/index.d.ts +46 -0
- package/dist/base/index.js +5 -0
- package/dist/base/kinds.d.ts +54 -0
- package/dist/base/kinds.js +78 -0
- package/dist/base/rules.d.ts +73 -0
- package/dist/base/rules.js +80 -0
- package/dist/drizzle/index.d.ts +438 -0
- package/dist/drizzle/index.js +832 -0
- package/dist/drizzle/kinds.d.ts +27 -0
- package/dist/drizzle/kinds.js +41 -0
- package/dist/drizzle/migrate.d.ts +133 -0
- package/dist/drizzle/migrate.js +1285 -0
- package/dist/drizzle/proxy/index.d.ts +1 -0
- package/dist/drizzle/proxy/index.js +1 -0
- package/dist/drizzle/proxy/node-postgres.d.ts +1 -0
- package/dist/drizzle/proxy/node-postgres.js +1 -0
- package/dist/drizzle/proxy/pg-core.d.ts +1 -0
- package/dist/drizzle/proxy/pg-core.js +1 -0
- package/dist/drizzle/rules.d.ts +336 -0
- package/dist/drizzle/rules.js +44 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +36 -0
- package/dist/mithaq/define.d.ts +288 -0
- package/dist/mithaq/define.js +43 -0
- package/dist/mithaq/generate-messages.d.ts +38 -0
- package/dist/mithaq/generate-messages.js +234 -0
- package/dist/mithaq/language.d.ts +335 -0
- package/dist/mithaq/language.js +76 -0
- package/dist/mithaq/lock.d.ts +71 -0
- package/dist/mithaq/lock.js +329 -0
- package/dist/mithaq/messages.d.ts +55 -0
- package/dist/mithaq/messages.js +106 -0
- package/dist/mithaq/refusal.d.ts +6 -0
- package/dist/mithaq/refusal.js +6 -0
- package/dist/mithaq/resolve.d.ts +10 -0
- package/dist/mithaq/resolve.js +954 -0
- package/dist/mithaq/rows.d.ts +87 -0
- package/dist/mithaq/rows.js +174 -0
- package/dist/mithaq/rukn.d.ts +72 -0
- package/dist/mithaq/rukn.js +15 -0
- package/dist/mithaq/standard-schema.d.ts +38 -0
- package/dist/mithaq/standard-schema.js +2 -0
- package/dist/mithaq/types.d.ts +358 -0
- package/dist/mithaq/types.js +15 -0
- package/dist/mithaq/user.d.ts +19 -0
- package/dist/mithaq/user.js +16 -0
- package/dist/mithaq/where.d.ts +32 -0
- package/dist/mithaq/where.js +87 -0
- package/dist/rbac/index.d.ts +105 -0
- package/dist/rbac/index.js +182 -0
- package/dist/rbac/steps.d.ts +22 -0
- package/dist/rbac/steps.js +161 -0
- package/dist/rich-text/index.d.ts +27 -0
- package/dist/rich-text/index.js +58 -0
- package/dist/rich-text/rich-text.d.ts +159 -0
- package/dist/rich-text/rich-text.js +372 -0
- package/dist/screen/client.d.ts +153 -0
- package/dist/screen/client.js +68 -0
- package/dist/screen/generate.d.ts +14 -0
- package/dist/screen/generate.js +226 -0
- package/dist/screen/index.d.ts +479 -0
- package/dist/screen/index.js +645 -0
- package/dist/screen/react.d.ts +95 -0
- package/dist/screen/react.js +58 -0
- package/dist/screen/studio.d.ts +24 -0
- package/dist/screen/studio.js +68 -0
- package/dist/service/index.d.ts +63 -0
- package/dist/service/index.js +15 -0
- package/dist/storage/allowed-type.d.ts +5 -0
- package/dist/storage/allowed-type.js +7 -0
- package/dist/storage/index.d.ts +43 -0
- package/dist/storage/index.js +44 -0
- package/dist/storage/storage.d.ts +384 -0
- package/dist/storage/storage.js +405 -0
- package/dist/versions/index.d.ts +37 -0
- package/dist/versions/index.js +8 -0
- package/dist/versions/versions.d.ts +104 -0
- package/dist/versions/versions.js +160 -0
- package/dist/zod/index.d.ts +184 -0
- package/dist/zod/index.js +121 -0
- package/dist/zod/kinds.d.ts +34 -0
- package/dist/zod/kinds.js +49 -0
- package/dist/zod/rules.d.ts +117 -0
- package/dist/zod/rules.js +67 -0
- package/package.json +63 -4
- package/r/mithaq-cells.json +20 -0
- package/r/mithaq-controls.json +37 -0
- package/r/mithaq-directional-icon.json +15 -0
- package/r/mithaq-expected-updated-at.json +15 -0
- package/r/mithaq-field-shell.json +18 -0
- package/r/mithaq-filter-operators.json +15 -0
- package/r/mithaq-form.json +33 -0
- package/r/mithaq-list-columns.json +23 -0
- package/r/mithaq-list-filters.json +24 -0
- package/r/mithaq-list-pagination.json +24 -0
- package/r/mithaq-list-query.json +18 -0
- package/r/mithaq-list-selection.json +19 -0
- package/r/mithaq-list.json +33 -0
- package/r/mithaq-nav.json +24 -0
- package/r/mithaq-nodes.json +34 -0
- package/r/mithaq-relationship-cell.json +20 -0
- package/r/mithaq-relationship-control.json +20 -0
- package/r/mithaq-rich-text.json +40 -0
- package/r/mithaq-screens-host.json +96 -0
- package/r/mithaq-storage.json +44 -0
- package/r/mithaq-upload.json +29 -0
- package/r/registry.json +550 -0
- package/README.md +0 -3
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { type SQLWrapper } from 'drizzle-orm';
|
|
2
|
+
import { type AssignedResolver, type AuthStrategy, type LocalAuthPermissions } from '../../asas/actor.ts';
|
|
3
|
+
import type { ResolvedKayan } from '../../mithaq/types.ts';
|
|
4
|
+
import { neverRead, type DerivedShapes, type WriteStep } from '../../asas/runner/steps.ts';
|
|
5
|
+
import type { StandardSchemaV1 } from '../../mithaq/standard-schema.ts';
|
|
6
|
+
type Row = Record<string, unknown>;
|
|
7
|
+
type Selected = {
|
|
8
|
+
limit(count: number): Promise<Row[]>;
|
|
9
|
+
where(condition: unknown): {
|
|
10
|
+
limit(count: number): Promise<Row[]>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type Db = {
|
|
14
|
+
execute(query: unknown): Promise<unknown>;
|
|
15
|
+
select(): {
|
|
16
|
+
from(table: unknown): Selected;
|
|
17
|
+
};
|
|
18
|
+
update(table: unknown): {
|
|
19
|
+
set(values: Row): {
|
|
20
|
+
where(condition: unknown): {
|
|
21
|
+
returning(): Promise<Row[]>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
transaction<Result>(run: (tx: Db) => Promise<Result>): Promise<Result>;
|
|
26
|
+
};
|
|
27
|
+
/** How long a token and its session live, in seconds. */
|
|
28
|
+
export declare const defaultTokenExpiration = 7200;
|
|
29
|
+
/** Failed logins before the account locks. */
|
|
30
|
+
export declare const defaultMaxLoginAttempts = 5;
|
|
31
|
+
/** How long the lock holds, in milliseconds. */
|
|
32
|
+
export declare const defaultLockTime = 600000;
|
|
33
|
+
export type LocalAuthOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* Signs with a random per-process secret when no `secret` is passed, and sends
|
|
36
|
+
* cookies without `Secure`. Never in production.
|
|
37
|
+
*/
|
|
38
|
+
development?: boolean;
|
|
39
|
+
secureCookies?: boolean;
|
|
40
|
+
/** What every token is signed with, 32 characters at least. Required unless `development` or `withoutSecret` is set. */
|
|
41
|
+
secret?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The project's own words local auth answers every POST with, as a 503, when it has no
|
|
44
|
+
* `secret` outside development; local auth is then off as a whole. Without it, a missing secret fails the build.
|
|
45
|
+
*/
|
|
46
|
+
withoutSecret?: string;
|
|
47
|
+
/** How long a token and its session live, in seconds. */
|
|
48
|
+
tokenExpiration: number;
|
|
49
|
+
/** Failed logins before the account locks; 0 turns the lockout off. */
|
|
50
|
+
maxLoginAttempts: number;
|
|
51
|
+
/** How long the lock holds, in milliseconds. */
|
|
52
|
+
lockTime: number;
|
|
53
|
+
/**
|
|
54
|
+
* Where the verification and reset tokens go: the project renders and sends the whole mail.
|
|
55
|
+
* Without it, tokens are printed in development only, and outside development none is minted.
|
|
56
|
+
*/
|
|
57
|
+
email?: {
|
|
58
|
+
send: (message: {
|
|
59
|
+
to: string;
|
|
60
|
+
kind: 'verification' | 'reset';
|
|
61
|
+
token: string;
|
|
62
|
+
user: Row;
|
|
63
|
+
}) => Promise<void>;
|
|
64
|
+
};
|
|
65
|
+
/** The context every step of first registration reads, built by the project's own code from the request. */
|
|
66
|
+
context?: (request: Request) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
67
|
+
/**
|
|
68
|
+
* The address a request came from, as the project's server saw it; mithaq reads no header for it.
|
|
69
|
+
* `login`, `forgot-password` and `reset-password` are rate limited by it; `null` leaves a request uncounted.
|
|
70
|
+
*/
|
|
71
|
+
ip: (request: Request) => string | null | undefined | Promise<string | null | undefined>;
|
|
72
|
+
};
|
|
73
|
+
/** The store local auth reads its kayan through: the drizzle adapter, which declares `sql`. */
|
|
74
|
+
export type LocalAuthTarget = {
|
|
75
|
+
readonly sql: 'drizzle';
|
|
76
|
+
db: Db;
|
|
77
|
+
tables: Record<string, Record<string, SQLWrapper>>;
|
|
78
|
+
};
|
|
79
|
+
export declare const isLocalAuthTarget: <T extends {
|
|
80
|
+
readonly sql?: 'drizzle';
|
|
81
|
+
}>(target: T) => target is T & LocalAuthTarget;
|
|
82
|
+
export type Writes = Record<string, {
|
|
83
|
+
operations: {
|
|
84
|
+
create(data: Row): Promise<Row>;
|
|
85
|
+
};
|
|
86
|
+
}>;
|
|
87
|
+
type PublicLocalUser<User extends Row> = Omit<User, ProtectedLocalField>;
|
|
88
|
+
export type LocalAuthActor<KayanName extends string = string, User extends Row = Row> = PublicLocalUser<User> & {
|
|
89
|
+
kayan: KayanName;
|
|
90
|
+
strategy: 'local';
|
|
91
|
+
collection: KayanName;
|
|
92
|
+
/** The keys the build's access target resolved for this actor, never a column of this kayan's row. */
|
|
93
|
+
permissions?: '*' | readonly string[];
|
|
94
|
+
/** The role slugs the access target resolved in the tenant the actor's row names. */
|
|
95
|
+
roles?: readonly string[];
|
|
96
|
+
user: PublicLocalUser<User>;
|
|
97
|
+
};
|
|
98
|
+
declare const verifiedWrite: ({ user, siblingData }: {
|
|
99
|
+
user?: unknown;
|
|
100
|
+
siblingData?: Record<string, unknown>;
|
|
101
|
+
}) => boolean;
|
|
102
|
+
/**
|
|
103
|
+
* The fields a kayan carrying `local()` spreads beside `defaultFields`. Every one but `email`
|
|
104
|
+
* and `_verified` is closed on read and supplied by the provider alone.
|
|
105
|
+
*/
|
|
106
|
+
export declare const localAuthFields: {
|
|
107
|
+
readonly email: {
|
|
108
|
+
readonly kind: 'email';
|
|
109
|
+
readonly rules: {
|
|
110
|
+
readonly required: true;
|
|
111
|
+
readonly unique: true;
|
|
112
|
+
readonly lowercase: true;
|
|
113
|
+
readonly trim: true;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
readonly hash: {
|
|
117
|
+
readonly kind: 'text';
|
|
118
|
+
readonly access: {
|
|
119
|
+
read: typeof neverRead;
|
|
120
|
+
};
|
|
121
|
+
readonly rules: {
|
|
122
|
+
readonly required: true;
|
|
123
|
+
readonly providedBy: {
|
|
124
|
+
readonly create: 'application';
|
|
125
|
+
readonly update: 'application';
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
readonly salt: {
|
|
130
|
+
readonly kind: 'text';
|
|
131
|
+
readonly access: {
|
|
132
|
+
read: typeof neverRead;
|
|
133
|
+
};
|
|
134
|
+
readonly rules: {
|
|
135
|
+
readonly required: true;
|
|
136
|
+
readonly providedBy: {
|
|
137
|
+
readonly create: 'application';
|
|
138
|
+
readonly update: 'application';
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
readonly sessions: {
|
|
143
|
+
readonly kind: 'text';
|
|
144
|
+
readonly access: {
|
|
145
|
+
read: typeof neverRead;
|
|
146
|
+
};
|
|
147
|
+
readonly rules: {
|
|
148
|
+
readonly providedBy: {
|
|
149
|
+
readonly create: 'application';
|
|
150
|
+
readonly update: 'application';
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
readonly loginAttempts: {
|
|
155
|
+
readonly kind: 'number';
|
|
156
|
+
readonly access: {
|
|
157
|
+
read: typeof neverRead;
|
|
158
|
+
};
|
|
159
|
+
readonly rules: {
|
|
160
|
+
readonly defaultValue: 0;
|
|
161
|
+
readonly providedBy: {
|
|
162
|
+
readonly create: 'application';
|
|
163
|
+
readonly update: 'application';
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
readonly lockUntil: {
|
|
168
|
+
readonly kind: 'datetime';
|
|
169
|
+
readonly access: {
|
|
170
|
+
read: typeof neverRead;
|
|
171
|
+
};
|
|
172
|
+
readonly rules: {
|
|
173
|
+
readonly providedBy: {
|
|
174
|
+
readonly create: 'application';
|
|
175
|
+
readonly update: 'application';
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
readonly resetPasswordToken: {
|
|
180
|
+
readonly kind: 'text';
|
|
181
|
+
readonly access: {
|
|
182
|
+
read: typeof neverRead;
|
|
183
|
+
};
|
|
184
|
+
readonly rules: {
|
|
185
|
+
readonly providedBy: {
|
|
186
|
+
readonly create: 'application';
|
|
187
|
+
readonly update: 'application';
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
readonly resetPasswordAttempts: {
|
|
192
|
+
readonly kind: 'number';
|
|
193
|
+
readonly access: {
|
|
194
|
+
read: typeof neverRead;
|
|
195
|
+
};
|
|
196
|
+
readonly rules: {
|
|
197
|
+
readonly defaultValue: 0;
|
|
198
|
+
readonly providedBy: {
|
|
199
|
+
readonly create: 'application';
|
|
200
|
+
readonly update: 'application';
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
readonly resetPasswordExpiration: {
|
|
205
|
+
readonly kind: 'datetime';
|
|
206
|
+
readonly access: {
|
|
207
|
+
read: typeof neverRead;
|
|
208
|
+
};
|
|
209
|
+
readonly rules: {
|
|
210
|
+
readonly providedBy: {
|
|
211
|
+
readonly create: 'application';
|
|
212
|
+
readonly update: 'application';
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
readonly _verified: {
|
|
217
|
+
readonly kind: 'checkbox';
|
|
218
|
+
readonly access: {
|
|
219
|
+
readonly create: typeof verifiedWrite;
|
|
220
|
+
readonly update: typeof verifiedWrite;
|
|
221
|
+
};
|
|
222
|
+
readonly rules: {
|
|
223
|
+
readonly defaultValue: false;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
readonly _verificationToken: {
|
|
227
|
+
readonly kind: 'text';
|
|
228
|
+
readonly access: {
|
|
229
|
+
read: typeof neverRead;
|
|
230
|
+
};
|
|
231
|
+
readonly rules: {
|
|
232
|
+
readonly providedBy: {
|
|
233
|
+
readonly create: 'application';
|
|
234
|
+
readonly update: 'application';
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
type Shipped = typeof localAuthFields;
|
|
240
|
+
/** The fields `localAuthFields` closes on read, which a response never carries. */
|
|
241
|
+
export type ProtectedLocalField = {
|
|
242
|
+
[Name in keyof Shipped]: Shipped[Name] extends {
|
|
243
|
+
access: {
|
|
244
|
+
read: unknown;
|
|
245
|
+
};
|
|
246
|
+
} ? Name : never;
|
|
247
|
+
}[keyof Shipped];
|
|
248
|
+
export declare const holdsVerificationSteps: (kayan: ResolvedKayan) => boolean;
|
|
249
|
+
/**
|
|
250
|
+
* The `create` and `update` a kayan carrying `local()` spreads over `defaultOperations`.
|
|
251
|
+
* A kayan adding a step writes the list around them: `[...localAuthOperations.create.steps, notify]`.
|
|
252
|
+
*/
|
|
253
|
+
export declare const localAuthOperations: {
|
|
254
|
+
create: {
|
|
255
|
+
input: ({ create }: DerivedShapes) => StandardSchemaV1<Record<string, unknown> & {
|
|
256
|
+
password?: string;
|
|
257
|
+
}>;
|
|
258
|
+
steps: WriteStep[];
|
|
259
|
+
};
|
|
260
|
+
update: {
|
|
261
|
+
input: ({ update: shape }: DerivedShapes) => StandardSchemaV1<Record<string, unknown> & {
|
|
262
|
+
password?: string;
|
|
263
|
+
}>;
|
|
264
|
+
steps: WriteStep[];
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
/** The local email-and-password strategy: sessions on the user row, and a signed cookie naming one. */
|
|
268
|
+
export declare const localAuthStrategy: <Name extends string = string>({ options, kayan: resolved, target, writes, projectUser, permissions, assigned, onError, }: {
|
|
269
|
+
options: LocalAuthOptions;
|
|
270
|
+
kayan: ResolvedKayan;
|
|
271
|
+
target: LocalAuthTarget;
|
|
272
|
+
writes: Writes;
|
|
273
|
+
/** What a response carries of a row this actor reads; required, since an identity would hand every field to every caller. */
|
|
274
|
+
projectUser: (row: Row, actor: LocalAuthActor<Name>) => Promise<Row>;
|
|
275
|
+
permissions?: LocalAuthPermissions;
|
|
276
|
+
assigned?: AssignedResolver;
|
|
277
|
+
/** Handed an access target that failed to answer, and a reset token `forgot-password` could not hand over. */
|
|
278
|
+
onError: (error: unknown) => void;
|
|
279
|
+
}) => AuthStrategy<LocalAuthActor<Name>>;
|
|
280
|
+
/** The local email-and-password provider as a kayan declares it: `auth: local({ ... })`. */
|
|
281
|
+
export declare const local: (options: LocalAuthOptions) => {
|
|
282
|
+
provider: 'local';
|
|
283
|
+
options: LocalAuthOptions;
|
|
284
|
+
};
|
|
285
|
+
export {};
|