@drhomet/mithaq 0.0.0-stage → 0.2.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/LICENSE +22 -0
- package/LICENSES/openstatus-time-picker.txt +21 -0
- package/LICENSES/payload.txt +22 -0
- package/LICENSES/ponytail.txt +21 -0
- package/README.md +160 -2
- package/dist/asas/actor.d.ts +96 -0
- package/dist/asas/actor.js +114 -0
- package/dist/asas/build.d.ts +239 -0
- package/dist/asas/build.js +834 -0
- package/dist/asas/cli/mithaq.d.ts +2 -0
- package/dist/asas/cli/mithaq.js +177 -0
- package/dist/asas/cli/upgrade.d.ts +33 -0
- package/dist/asas/cli/upgrade.js +256 -0
- package/dist/asas/http/fetch.d.ts +41 -0
- package/dist/asas/http/fetch.js +178 -0
- package/dist/asas/http/orpc.d.ts +45 -0
- package/dist/asas/http/orpc.js +153 -0
- package/dist/asas/runner/bulk.d.ts +20 -0
- package/dist/asas/runner/bulk.js +196 -0
- package/dist/asas/runner/errors.d.ts +63 -0
- package/dist/asas/runner/errors.js +75 -0
- package/dist/asas/runner/read.d.ts +72 -0
- package/dist/asas/runner/read.js +601 -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 +418 -0
- package/dist/asas/runner/steps.js +277 -0
- package/dist/asas/runner/store.d.ts +4 -0
- package/dist/asas/runner/store.js +21 -0
- package/dist/asas/runner/tenant.d.ts +54 -0
- package/dist/asas/runner/tenant.js +275 -0
- package/dist/asas/runner/write.d.ts +606 -0
- package/dist/asas/runner/write.js +1019 -0
- package/dist/auth/better-auth/access.d.ts +29 -0
- package/dist/auth/better-auth/access.js +103 -0
- package/dist/auth/better-auth/generate.d.ts +31 -0
- package/dist/auth/better-auth/generate.js +328 -0
- package/dist/auth/better-auth/index.d.ts +94 -0
- package/dist/auth/better-auth/index.js +81 -0
- package/dist/auth/better-auth/tenant.d.ts +26 -0
- package/dist/auth/better-auth/tenant.js +34 -0
- package/dist/auth/local/index.d.ts +285 -0
- package/dist/auth/local/index.js +738 -0
- package/dist/base/decimal.d.ts +9 -0
- package/dist/base/decimal.js +16 -0
- package/dist/base/fields.d.ts +124 -0
- package/dist/base/fields.js +52 -0
- package/dist/base/index.d.ts +47 -0
- package/dist/base/index.js +5 -0
- package/dist/base/json-schema.d.ts +7 -0
- package/dist/base/json-schema.js +35 -0
- package/dist/base/kinds.d.ts +75 -0
- package/dist/base/kinds.js +123 -0
- package/dist/base/rules.d.ts +73 -0
- package/dist/base/rules.js +81 -0
- package/dist/drizzle/index.d.ts +308 -0
- package/dist/drizzle/index.js +951 -0
- package/dist/drizzle/kinds.d.ts +28 -0
- package/dist/drizzle/kinds.js +43 -0
- package/dist/drizzle/migrate.d.ts +159 -0
- package/dist/drizzle/migrate.js +1328 -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 +35 -0
- package/dist/index.js +26 -0
- package/dist/mithaq/define.d.ts +335 -0
- package/dist/mithaq/define.js +57 -0
- package/dist/mithaq/generate-messages.d.ts +38 -0
- package/dist/mithaq/generate-messages.js +235 -0
- package/dist/mithaq/language.d.ts +374 -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/message-file.d.ts +13 -0
- package/dist/mithaq/message-file.js +29 -0
- package/dist/mithaq/messages.d.ts +55 -0
- package/dist/mithaq/messages.js +111 -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 +1014 -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 +386 -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 +28 -0
- package/dist/rich-text/index.js +59 -0
- package/dist/rich-text/rich-text.d.ts +106 -0
- package/dist/rich-text/rich-text.js +249 -0
- package/dist/rich-text/value.d.ts +55 -0
- package/dist/rich-text/value.js +126 -0
- package/dist/screen/client.d.ts +156 -0
- package/dist/screen/client.js +71 -0
- package/dist/screen/generate.d.ts +14 -0
- package/dist/screen/generate.js +268 -0
- package/dist/screen/index.d.ts +496 -0
- package/dist/screen/index.js +663 -0
- package/dist/screen/react.d.ts +97 -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 +42 -0
- package/dist/storage/index.js +43 -0
- package/dist/storage/storage.d.ts +386 -0
- package/dist/storage/storage.js +412 -0
- package/dist/targets.d.ts +14 -0
- package/dist/targets.js +16 -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/vite.d.ts +7 -0
- package/dist/vite.js +81 -0
- package/dist/zod/index.d.ts +193 -0
- package/dist/zod/index.js +122 -0
- package/dist/zod/kinds.d.ts +36 -0
- package/dist/zod/kinds.js +58 -0
- package/dist/zod/rules.d.ts +117 -0
- package/dist/zod/rules.js +67 -0
- package/docs/packages/mithaq/README.md +962 -0
- package/docs/packages/mithaq/src/asas/cli/README.md +252 -0
- package/docs/packages/mithaq/src/asas/runner/README.md +472 -0
- package/docs/packages/mithaq/src/drizzle/README.md +39 -0
- package/docs/packages/mithaq-admin/README.md +312 -0
- package/docs/templates/asas/README.md +1056 -0
- package/package.json +92 -4
- package/skills/add-field/SKILL.md +27 -0
- package/skills/add-kayan/SKILL.md +26 -0
- package/skills/eject-admin-piece/SKILL.md +28 -0
- package/skills/upgrade-mithaq/SKILL.md +35 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Both HTTP plugs read the code from here, so a refusal answers the same through either.
|
|
2
|
+
export const codes = {
|
|
3
|
+
400: 'BAD_REQUEST',
|
|
4
|
+
401: 'UNAUTHORIZED',
|
|
5
|
+
403: 'FORBIDDEN',
|
|
6
|
+
404: 'NOT_FOUND',
|
|
7
|
+
409: 'CONFLICT',
|
|
8
|
+
413: 'PAYLOAD_TOO_LARGE',
|
|
9
|
+
429: 'TOO_MANY_REQUESTS',
|
|
10
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A refusal the caller caused, with the HTTP status, a message `key` a client
|
|
14
|
+
* translates, and the `params` the message names. The English message is for logs.
|
|
15
|
+
*/
|
|
16
|
+
export class AsasError extends Error {
|
|
17
|
+
status;
|
|
18
|
+
key;
|
|
19
|
+
params;
|
|
20
|
+
constructor(message, status, key, params = {}, cause) {
|
|
21
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.key = key;
|
|
24
|
+
this.params = params;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** A write committed, but one or more callbacks that followed it failed. */
|
|
28
|
+
export class AfterCommitError extends Error {
|
|
29
|
+
committed = true;
|
|
30
|
+
result;
|
|
31
|
+
constructor(result, cause) {
|
|
32
|
+
super('The write committed, but an afterCommit step failed.', { cause });
|
|
33
|
+
this.result = result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Something a project is told that is expected rather than a failure, handed to the same `onError`. */
|
|
37
|
+
export class Notice extends Error {
|
|
38
|
+
name = 'Notice';
|
|
39
|
+
}
|
|
40
|
+
/** A generic wire signal; callback details remain in the server reporter. */
|
|
41
|
+
export const afterCommitHeader = 'x-mithaq-after-commit';
|
|
42
|
+
/** The caller may not do this. */
|
|
43
|
+
export const denied = ({ message, key, params, cause }) => new AsasError(message, 403, key, params, cause);
|
|
44
|
+
/** The caller sent something the schema or the shape refuses. */
|
|
45
|
+
export const invalid = ({ message, key, params, cause }) => new AsasError(message, 400, key, params, cause);
|
|
46
|
+
/**
|
|
47
|
+
* The row the caller addressed is not there. An absent row and one access
|
|
48
|
+
* excludes answer alike, so a 404 never says which.
|
|
49
|
+
*/
|
|
50
|
+
export const missing = ({ message, key, params, cause }) => new AsasError(message, 404, key, params, cause);
|
|
51
|
+
/**
|
|
52
|
+
* The write cannot complete, as a 409. Its key says whether trying again can help.
|
|
53
|
+
* It never says which column or whose row it hit.
|
|
54
|
+
*/
|
|
55
|
+
export const conflict = ({ message, key, params, cause }) => new AsasError(message, 409, key, params, cause);
|
|
56
|
+
/** A transaction the database rolled back may be retried, without exposing its query or rows. */
|
|
57
|
+
export const retryConflict = (thrown) => {
|
|
58
|
+
if (thrown instanceof AsasError || thrown instanceof AfterCommitError)
|
|
59
|
+
return thrown;
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
for (let cause = thrown; cause && typeof cause === 'object' && !seen.has(cause); cause = cause.cause) {
|
|
62
|
+
if (cause instanceof AfterCommitError)
|
|
63
|
+
return thrown;
|
|
64
|
+
seen.add(cause);
|
|
65
|
+
if (['40P01', '40001'].includes(String(cause.code))) {
|
|
66
|
+
return conflict({ message: 'The transaction conflicted with another write. Try again.', key: 'error.conflict.retry', cause: thrown });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return thrown;
|
|
70
|
+
};
|
|
71
|
+
// Shared by the read layer, which answers the caller with a 400, and the drizzle
|
|
72
|
+
// store, which throws at the access callback that built the query.
|
|
73
|
+
export const localizedQuery = ({ kayan, field, what, locales = [], }) => what === 'sort'
|
|
74
|
+
? `Kayan "${kayan}" field "${field}" is localized, so it is one column per locale and no sort can name it. A sort that names one locale is not built. Name a field that is not localized, or read the rows and pick the locale in the app.`
|
|
75
|
+
: `Kayan "${kayan}" field "${field}" is localized, so it is one column per locale and no filter can name the field itself. Name the locale as a second path segment instead, ${locales.map((locale) => `"${field}.${locale}"`).join(' or ')}. That path is one hop only, so a localized field reached across a relationship cannot name its locale.`;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Authorize, type ManagedAdmin, type ReadOptions } from './write.ts';
|
|
2
|
+
import { type Where } from '../../mithaq/where.ts';
|
|
3
|
+
import { type AuditHandler, type ReadTools, type ResolvedOperation } from './steps.ts';
|
|
4
|
+
import type { StandardSchemaV1 } from '../../mithaq/standard-schema.ts';
|
|
5
|
+
import { type ResolvedField, type ResolvedKayan } from '../../mithaq/types.ts';
|
|
6
|
+
import type { Store } from '../../mithaq/language.ts';
|
|
7
|
+
import { type TenantScope } from './tenant.ts';
|
|
8
|
+
/** What a `find` list takes where it declares no input of its own. */
|
|
9
|
+
export type FindInput = {
|
|
10
|
+
/** How far a read populates its `join` fields: 0 populates nothing, each level through the child kayan's own managed read. */
|
|
11
|
+
depth?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
page?: number;
|
|
14
|
+
sort?: string;
|
|
15
|
+
where?: Where;
|
|
16
|
+
};
|
|
17
|
+
export type Paginated<Row> = {
|
|
18
|
+
docs: Row[];
|
|
19
|
+
hasNextPage: boolean;
|
|
20
|
+
hasPrevPage: boolean;
|
|
21
|
+
limit: number;
|
|
22
|
+
nextPage: number | null;
|
|
23
|
+
page: number;
|
|
24
|
+
pagingCounter: number;
|
|
25
|
+
prevPage: number | null;
|
|
26
|
+
totalDocs: number;
|
|
27
|
+
totalPages: number;
|
|
28
|
+
};
|
|
29
|
+
export type ReaderMap<Actor = unknown> = {
|
|
30
|
+
operation: (args: {
|
|
31
|
+
name: string;
|
|
32
|
+
declaration: ResolvedOperation;
|
|
33
|
+
input: StandardSchemaV1;
|
|
34
|
+
output: StandardSchemaV1;
|
|
35
|
+
/** What a draft or a version is read back through, where the kayan keeps drafts or versions. */
|
|
36
|
+
draftOutput?: StandardSchemaV1;
|
|
37
|
+
}) => (data?: Record<string, unknown>, options?: ReadOptions<Actor>) => Promise<Record<string, unknown> | null | Paginated<Record<string, unknown>>>;
|
|
38
|
+
};
|
|
39
|
+
export declare const assertReadableWhere: <Actor>({ kayan, where, actor, authorize, admin, }: {
|
|
40
|
+
kayan: ResolvedKayan;
|
|
41
|
+
where: Where | undefined;
|
|
42
|
+
actor: Actor | null;
|
|
43
|
+
authorize: Authorize;
|
|
44
|
+
admin?: ManagedAdmin<Actor>;
|
|
45
|
+
}) => Promise<Where | undefined>;
|
|
46
|
+
/** The caller's own `where`, refused as a 400 where its grammar is malformed or a value is not of its column's kind. */
|
|
47
|
+
export declare const checkedWhere: (kayan: ResolvedKayan, where: unknown) => Promise<Where>;
|
|
48
|
+
export declare const readers: <Actor>({ kayan, store, cap, defaultLimit, joinLimit, admin, authorize, kayans, of, audit, catalog, openTenant, tenantOf, pickers, }: {
|
|
49
|
+
kayan: ResolvedKayan;
|
|
50
|
+
store: Store;
|
|
51
|
+
cap: number;
|
|
52
|
+
/** The service target's page where a caller names none. */
|
|
53
|
+
defaultLimit: number;
|
|
54
|
+
/** The service target's join page where a join field names none. */
|
|
55
|
+
joinLimit: number;
|
|
56
|
+
admin: ManagedAdmin<Actor> | undefined;
|
|
57
|
+
authorize: Authorize;
|
|
58
|
+
kayans: (effect: 'read') => unknown;
|
|
59
|
+
of: ReadTools['of'];
|
|
60
|
+
audit?: AuditHandler<Actor>;
|
|
61
|
+
catalog?: readonly string[];
|
|
62
|
+
/** Reads a read's `tenant` option into the scope every managed call under it keeps. */
|
|
63
|
+
openTenant: (args: {
|
|
64
|
+
actor: unknown;
|
|
65
|
+
reach: unknown;
|
|
66
|
+
kayan: ResolvedKayan;
|
|
67
|
+
}) => Promise<TenantScope | undefined>;
|
|
68
|
+
/** The organization the actor's session names, which a step reads as `ctx.tenant`. */
|
|
69
|
+
tenantOf: (actor: unknown) => string | undefined;
|
|
70
|
+
/** Every relationship field pointing at this kayan, by `<kayan>.<field>`, which a picker's read names as `for`. */
|
|
71
|
+
pickers?: Readonly<Record<string, ResolvedField>>;
|
|
72
|
+
}) => ReaderMap<Actor>;
|