@diphyx/harlemify 3.0.0 → 4.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/README.md +51 -32
- package/dist/module.d.mts +24 -13
- package/dist/module.d.ts +24 -13
- package/dist/module.json +1 -1
- package/dist/module.mjs +8 -10
- package/dist/runtime/composables/action.d.ts +4 -0
- package/dist/runtime/composables/action.js +8 -0
- package/dist/runtime/config.d.ts +10 -0
- package/dist/runtime/config.js +7 -0
- package/dist/runtime/core/layers/action.d.ts +4 -0
- package/dist/runtime/core/layers/action.js +102 -0
- package/dist/runtime/core/layers/model.d.ts +3 -0
- package/dist/runtime/core/layers/model.js +31 -0
- package/dist/runtime/core/layers/shape.d.ts +45 -0
- package/dist/runtime/core/layers/shape.js +56 -0
- package/dist/runtime/core/layers/view.d.ts +4 -0
- package/dist/runtime/core/layers/view.js +21 -0
- package/dist/runtime/core/store.d.ts +20 -66
- package/dist/runtime/core/store.js +46 -574
- package/dist/runtime/core/types/action.d.ts +163 -0
- package/dist/runtime/core/types/action.js +39 -0
- package/dist/runtime/core/types/model.d.ts +70 -0
- package/dist/runtime/core/types/model.js +5 -0
- package/dist/runtime/core/types/shape.d.ts +46 -0
- package/dist/runtime/core/types/shape.js +0 -0
- package/dist/runtime/core/types/view.d.ts +29 -0
- package/dist/runtime/core/types/view.js +0 -0
- package/dist/runtime/core/utils/action.d.ts +4 -0
- package/dist/runtime/core/utils/action.js +294 -0
- package/dist/runtime/core/utils/model.d.ts +12 -0
- package/dist/runtime/core/utils/model.js +227 -0
- package/dist/runtime/core/utils/shape.d.ts +3 -0
- package/dist/runtime/core/utils/shape.js +29 -0
- package/dist/runtime/core/utils/view.d.ts +5 -0
- package/dist/runtime/core/utils/view.js +19 -0
- package/dist/runtime/index.d.ts +8 -16
- package/dist/runtime/index.js +11 -7
- package/dist/runtime/plugin.js +2 -5
- package/package.json +2 -1
- package/dist/runtime/composables/use.d.ts +0 -22
- package/dist/runtime/composables/use.js +0 -14
- package/dist/runtime/core/api.d.ts +0 -37
- package/dist/runtime/core/api.js +0 -56
- package/dist/runtime/shared.d.ts +0 -9
- package/dist/runtime/shared.js +0 -3
- package/dist/runtime/utils/adapter.d.ts +0 -24
- package/dist/runtime/utils/adapter.js +0 -35
- package/dist/runtime/utils/cache.d.ts +0 -10
- package/dist/runtime/utils/cache.js +0 -26
- package/dist/runtime/utils/endpoint.d.ts +0 -38
- package/dist/runtime/utils/endpoint.js +0 -56
- package/dist/runtime/utils/errors.d.ts +0 -22
- package/dist/runtime/utils/errors.js +0 -33
- package/dist/runtime/utils/memory.d.ts +0 -40
- package/dist/runtime/utils/memory.js +0 -87
- package/dist/runtime/utils/schema.d.ts +0 -23
- package/dist/runtime/utils/schema.js +0 -58
- package/dist/runtime/utils/transform.d.ts +0 -6
- package/dist/runtime/utils/transform.js +0 -22
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { capitalize } from "./transform.js";
|
|
2
|
-
export var EndpointMethod = /* @__PURE__ */ ((EndpointMethod2) => {
|
|
3
|
-
EndpointMethod2["GET"] = "get";
|
|
4
|
-
EndpointMethod2["POST"] = "post";
|
|
5
|
-
EndpointMethod2["PUT"] = "put";
|
|
6
|
-
EndpointMethod2["PATCH"] = "patch";
|
|
7
|
-
EndpointMethod2["DELETE"] = "delete";
|
|
8
|
-
return EndpointMethod2;
|
|
9
|
-
})(EndpointMethod || {});
|
|
10
|
-
export var EndpointStatus = /* @__PURE__ */ ((EndpointStatus2) => {
|
|
11
|
-
EndpointStatus2["IDLE"] = "idle";
|
|
12
|
-
EndpointStatus2["PENDING"] = "pending";
|
|
13
|
-
EndpointStatus2["SUCCESS"] = "success";
|
|
14
|
-
EndpointStatus2["FAILED"] = "failed";
|
|
15
|
-
return EndpointStatus2;
|
|
16
|
-
})(EndpointStatus || {});
|
|
17
|
-
function createEndpointChain(method, url) {
|
|
18
|
-
return {
|
|
19
|
-
method,
|
|
20
|
-
url,
|
|
21
|
-
adapter: void 0,
|
|
22
|
-
withAdapter(adapter) {
|
|
23
|
-
return {
|
|
24
|
-
method,
|
|
25
|
-
url,
|
|
26
|
-
adapter
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export const Endpoint = {
|
|
32
|
-
get(url) {
|
|
33
|
-
return createEndpointChain("get" /* GET */, url);
|
|
34
|
-
},
|
|
35
|
-
post(url) {
|
|
36
|
-
return createEndpointChain("post" /* POST */, url);
|
|
37
|
-
},
|
|
38
|
-
put(url) {
|
|
39
|
-
return createEndpointChain("put" /* PUT */, url);
|
|
40
|
-
},
|
|
41
|
-
patch(url) {
|
|
42
|
-
return createEndpointChain("patch" /* PATCH */, url);
|
|
43
|
-
},
|
|
44
|
-
delete(url) {
|
|
45
|
-
return createEndpointChain("delete" /* DELETE */, url);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
export function makeEndpointStatusFlag(status) {
|
|
49
|
-
return `Is${capitalize(status)}`;
|
|
50
|
-
}
|
|
51
|
-
export function resolveEndpointUrl(endpoint, params) {
|
|
52
|
-
if (typeof endpoint.url === "function") {
|
|
53
|
-
return endpoint.url(params ?? {});
|
|
54
|
-
}
|
|
55
|
-
return endpoint.url;
|
|
56
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare enum ApiErrorSource {
|
|
2
|
-
REQUEST = "request",
|
|
3
|
-
RESPONSE = "response"
|
|
4
|
-
}
|
|
5
|
-
export interface ApiErrorOptions {
|
|
6
|
-
source: ApiErrorSource;
|
|
7
|
-
method: string;
|
|
8
|
-
url: string;
|
|
9
|
-
message?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class ApiError extends Error {
|
|
12
|
-
source: ApiErrorSource;
|
|
13
|
-
method: string;
|
|
14
|
-
url: string;
|
|
15
|
-
constructor(options: ApiErrorOptions);
|
|
16
|
-
}
|
|
17
|
-
export declare class ApiRequestError extends ApiError {
|
|
18
|
-
constructor(options: Omit<ApiErrorOptions, "source">);
|
|
19
|
-
}
|
|
20
|
-
export declare class ApiResponseError extends ApiError {
|
|
21
|
-
constructor(options: Omit<ApiErrorOptions, "source">);
|
|
22
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export var ApiErrorSource = /* @__PURE__ */ ((ApiErrorSource2) => {
|
|
2
|
-
ApiErrorSource2["REQUEST"] = "request";
|
|
3
|
-
ApiErrorSource2["RESPONSE"] = "response";
|
|
4
|
-
return ApiErrorSource2;
|
|
5
|
-
})(ApiErrorSource || {});
|
|
6
|
-
export class ApiError extends Error {
|
|
7
|
-
source;
|
|
8
|
-
method;
|
|
9
|
-
url;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
super(options.message ?? "Unknown error");
|
|
12
|
-
this.name = "ApiError";
|
|
13
|
-
this.source = options.source;
|
|
14
|
-
this.method = options.method;
|
|
15
|
-
this.url = options.url;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class ApiRequestError extends ApiError {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
super({
|
|
21
|
-
...options,
|
|
22
|
-
source: "request" /* REQUEST */
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export class ApiResponseError extends ApiError {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super({
|
|
29
|
-
...options,
|
|
30
|
-
source: "response" /* RESPONSE */
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export type MemoryTarget = "unit" | "units";
|
|
2
|
-
export type MemoryMutation = "set" | "edit" | "drop" | "add";
|
|
3
|
-
export interface EditOptions {
|
|
4
|
-
deep?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface AddOptions {
|
|
7
|
-
prepend?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface MemoryDefinition {
|
|
10
|
-
readonly on: MemoryTarget;
|
|
11
|
-
readonly path: string[];
|
|
12
|
-
readonly mutation?: MemoryMutation;
|
|
13
|
-
readonly prepend?: boolean;
|
|
14
|
-
readonly deep?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface UnitMemoryBuilder<_S = unknown> extends MemoryDefinition {
|
|
17
|
-
set(): MemoryDefinition;
|
|
18
|
-
edit(options?: EditOptions): MemoryDefinition;
|
|
19
|
-
drop(): MemoryDefinition;
|
|
20
|
-
}
|
|
21
|
-
export interface UnitsMemoryBuilder<_S = unknown> extends MemoryDefinition {
|
|
22
|
-
set(): MemoryDefinition;
|
|
23
|
-
edit(options?: EditOptions): MemoryDefinition;
|
|
24
|
-
drop(): MemoryDefinition;
|
|
25
|
-
add(options?: AddOptions): MemoryDefinition;
|
|
26
|
-
}
|
|
27
|
-
export interface UnitFunction<S> {
|
|
28
|
-
(): UnitMemoryBuilder<S>;
|
|
29
|
-
<K extends keyof S & string>(key: K): UnitMemoryBuilder<S[K]>;
|
|
30
|
-
<K extends keyof S & string, K2 extends keyof S[K] & string>(key: K, nested: K2): UnitMemoryBuilder<S[K][K2]>;
|
|
31
|
-
}
|
|
32
|
-
export interface UnitsFunction<S> {
|
|
33
|
-
(): UnitsMemoryBuilder<S>;
|
|
34
|
-
}
|
|
35
|
-
export interface MemoryBuilder<S = unknown> {
|
|
36
|
-
unit: UnitFunction<S>;
|
|
37
|
-
units: UnitsFunction<S>;
|
|
38
|
-
}
|
|
39
|
-
export declare function createMemoryBuilder<S>(): MemoryBuilder<S>;
|
|
40
|
-
export declare const Memory: MemoryBuilder<any>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
function createUnitMemoryBuilder(path = []) {
|
|
2
|
-
const definition = {
|
|
3
|
-
on: "unit",
|
|
4
|
-
path
|
|
5
|
-
};
|
|
6
|
-
return {
|
|
7
|
-
...definition,
|
|
8
|
-
set() {
|
|
9
|
-
return {
|
|
10
|
-
on: "unit",
|
|
11
|
-
path,
|
|
12
|
-
mutation: "set"
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
edit(options) {
|
|
16
|
-
return {
|
|
17
|
-
on: "unit",
|
|
18
|
-
path,
|
|
19
|
-
mutation: "edit",
|
|
20
|
-
deep: options?.deep
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
drop() {
|
|
24
|
-
return {
|
|
25
|
-
on: "unit",
|
|
26
|
-
path,
|
|
27
|
-
mutation: "drop"
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function createUnitsMemoryBuilder() {
|
|
33
|
-
const definition = {
|
|
34
|
-
on: "units",
|
|
35
|
-
path: []
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
...definition,
|
|
39
|
-
set() {
|
|
40
|
-
return {
|
|
41
|
-
on: "units",
|
|
42
|
-
path: [],
|
|
43
|
-
mutation: "set"
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
edit(options) {
|
|
47
|
-
return {
|
|
48
|
-
on: "units",
|
|
49
|
-
path: [],
|
|
50
|
-
mutation: "edit",
|
|
51
|
-
deep: options?.deep
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
drop() {
|
|
55
|
-
return {
|
|
56
|
-
on: "units",
|
|
57
|
-
path: [],
|
|
58
|
-
mutation: "drop"
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
add(options) {
|
|
62
|
-
return {
|
|
63
|
-
on: "units",
|
|
64
|
-
path: [],
|
|
65
|
-
mutation: "add",
|
|
66
|
-
prepend: options?.prepend
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function createUnitFunction() {
|
|
72
|
-
return function unit(...keys) {
|
|
73
|
-
return createUnitMemoryBuilder(keys);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function createUnitsFunction() {
|
|
77
|
-
return function units() {
|
|
78
|
-
return createUnitsMemoryBuilder();
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export function createMemoryBuilder() {
|
|
82
|
-
return {
|
|
83
|
-
unit: createUnitFunction(),
|
|
84
|
-
units: createUnitsFunction()
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export const Memory = createMemoryBuilder();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
export interface SchemaMeta<A extends string = string> {
|
|
3
|
-
indicator?: boolean;
|
|
4
|
-
actions?: A[];
|
|
5
|
-
}
|
|
6
|
-
export declare function getMeta(field: any): SchemaMeta | undefined;
|
|
7
|
-
export interface SchemaFieldInfo<A extends string = string> {
|
|
8
|
-
name: string;
|
|
9
|
-
indicator: boolean;
|
|
10
|
-
actions: A[];
|
|
11
|
-
}
|
|
12
|
-
export declare function getSchemaFields<T extends z.ZodRawShape, A extends string = string>(schema: z.ZodObject<T>): SchemaFieldInfo<A>[];
|
|
13
|
-
export declare function getFieldsForAction<T extends z.ZodRawShape, A extends string = string>(schema: z.ZodObject<T>, action: A): string[];
|
|
14
|
-
export interface ResolveSchemaOptions<S> {
|
|
15
|
-
indicator?: keyof S;
|
|
16
|
-
action?: string;
|
|
17
|
-
unit?: Partial<S>;
|
|
18
|
-
}
|
|
19
|
-
export declare function resolveSchema<T extends z.ZodRawShape, S extends z.infer<z.ZodObject<T>>>(schema: z.ZodObject<T>, options?: ResolveSchemaOptions<S>): {
|
|
20
|
-
indicator: keyof S;
|
|
21
|
-
keys: Record<keyof S, true>;
|
|
22
|
-
values: Partial<S>;
|
|
23
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export function getMeta(field) {
|
|
2
|
-
return field.meta();
|
|
3
|
-
}
|
|
4
|
-
const schemaFieldsCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
-
export function getSchemaFields(schema) {
|
|
6
|
-
const cached = schemaFieldsCache.get(schema);
|
|
7
|
-
if (cached) {
|
|
8
|
-
return cached;
|
|
9
|
-
}
|
|
10
|
-
const fields = [];
|
|
11
|
-
for (const key in schema.shape) {
|
|
12
|
-
const meta = getMeta(schema.shape[key]);
|
|
13
|
-
fields.push({
|
|
14
|
-
name: key,
|
|
15
|
-
indicator: meta?.indicator ?? false,
|
|
16
|
-
actions: meta?.actions ?? []
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
schemaFieldsCache.set(schema, fields);
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
22
|
-
export function getFieldsForAction(schema, action) {
|
|
23
|
-
const fields = [];
|
|
24
|
-
for (const key in schema.shape) {
|
|
25
|
-
const meta = getMeta(schema.shape[key]);
|
|
26
|
-
if (meta?.actions) {
|
|
27
|
-
const actionsSet = new Set(meta.actions);
|
|
28
|
-
if (actionsSet.has(action)) {
|
|
29
|
-
fields.push(key);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return fields;
|
|
34
|
-
}
|
|
35
|
-
export function resolveSchema(schema, options) {
|
|
36
|
-
const output = {
|
|
37
|
-
indicator: options?.indicator ?? "id",
|
|
38
|
-
keys: {},
|
|
39
|
-
values: {}
|
|
40
|
-
};
|
|
41
|
-
for (const key in schema.shape) {
|
|
42
|
-
const meta = getMeta(schema.shape[key]);
|
|
43
|
-
if (meta?.indicator) {
|
|
44
|
-
output.indicator = key;
|
|
45
|
-
}
|
|
46
|
-
if (!options?.action || !meta?.actions) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const actionsSet = new Set(meta.actions);
|
|
50
|
-
if (actionsSet.has(options.action)) {
|
|
51
|
-
output.keys[key] = true;
|
|
52
|
-
if (options?.unit && key in options.unit) {
|
|
53
|
-
output.values[key] = options.unit[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return output;
|
|
58
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type IsVowel<C extends string> = C extends "a" | "e" | "i" | "o" | "u" ? true : false;
|
|
2
|
-
export type Pluralize<S extends string> = S extends `${infer Base}y` ? Base extends `${infer _Rest}${infer Last}` ? IsVowel<Last> extends true ? `${S}s` : `${Base}ies` : `${S}s` : S extends `${string}${"s" | "x" | "z"}` ? `${S}es` : S extends `${string}${"ch" | "sh"}` ? `${S}es` : `${S}s`;
|
|
3
|
-
export declare function pluralize<S extends string>(word: S): Pluralize<S>;
|
|
4
|
-
export type Capitalize<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
5
|
-
export declare function capitalize<S extends string>(str: S): Capitalize<S>;
|
|
6
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const VOWELS = /* @__PURE__ */ new Set(["a", "e", "i", "o", "u"]);
|
|
2
|
-
const SIBILANTS = /* @__PURE__ */ new Set(["s", "x", "z"]);
|
|
3
|
-
const SIBILANT_PAIRS = /* @__PURE__ */ new Set(["ch", "sh"]);
|
|
4
|
-
export function pluralize(word) {
|
|
5
|
-
if (!word) return word;
|
|
6
|
-
const lastChar = word.slice(-1).toLowerCase();
|
|
7
|
-
const lastTwo = word.slice(-2).toLowerCase();
|
|
8
|
-
const beforeLast = word.slice(-2, -1).toLowerCase();
|
|
9
|
-
if (lastChar === "y" && !VOWELS.has(beforeLast)) {
|
|
10
|
-
return word.slice(0, -1) + "ies";
|
|
11
|
-
}
|
|
12
|
-
if (SIBILANTS.has(lastChar)) {
|
|
13
|
-
return word + "es";
|
|
14
|
-
}
|
|
15
|
-
if (SIBILANT_PAIRS.has(lastTwo)) {
|
|
16
|
-
return word + "es";
|
|
17
|
-
}
|
|
18
|
-
return word + "s";
|
|
19
|
-
}
|
|
20
|
-
export function capitalize(str) {
|
|
21
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
22
|
-
}
|