@diphyx/harlemify 0.0.2 → 1.0.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 +1 -1
- package/README.md +25 -27
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -0
- package/dist/runtime/composables/use.d.ts +30 -0
- package/dist/runtime/composables/use.js +25 -0
- package/dist/runtime/core/api.d.ts +14 -17
- package/dist/runtime/core/api.js +9 -15
- package/dist/runtime/core/store.d.ts +66 -98
- package/dist/runtime/core/store.js +179 -370
- package/dist/runtime/index.d.ts +7 -4
- package/dist/runtime/index.js +3 -14
- package/dist/runtime/plugin.js +1 -5
- package/dist/runtime/utils/endpoint.d.ts +14 -50
- package/dist/runtime/utils/endpoint.js +18 -19
- package/dist/runtime/utils/schema.d.ts +9 -4
- package/dist/runtime/utils/schema.js +6 -6
- package/dist/runtime/utils/transform.d.ts +6 -0
- package/dist/runtime/utils/transform.js +20 -0
- package/package.json +3 -2
|
@@ -1,395 +1,243 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from "@harlem/core";
|
|
2
|
+
import { createStore as createHarlemStore } from "@harlem/core";
|
|
3
|
+
import { createApi } from "./api.js";
|
|
5
4
|
import { resolveSchema } from "../utils/schema.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
import { pluralize } from "../utils/transform.js";
|
|
6
|
+
import { Endpoint, EndpointStatus, getEndpoint, makeEndpointStatusName, resolveEndpointUrl } from "../utils/endpoint.js";
|
|
7
|
+
export var StoreMemoryAction = /* @__PURE__ */ ((StoreMemoryAction2) => {
|
|
8
|
+
StoreMemoryAction2["SET"] = "set";
|
|
9
|
+
StoreMemoryAction2["EDIT"] = "edit";
|
|
10
|
+
StoreMemoryAction2["DROP"] = "drop";
|
|
11
|
+
return StoreMemoryAction2;
|
|
12
|
+
})(StoreMemoryAction || {});
|
|
14
13
|
export var StoreMemoryPosition = /* @__PURE__ */ ((StoreMemoryPosition2) => {
|
|
15
14
|
StoreMemoryPosition2["FIRST"] = "first";
|
|
16
15
|
StoreMemoryPosition2["LAST"] = "last";
|
|
17
16
|
return StoreMemoryPosition2;
|
|
18
17
|
})(StoreMemoryPosition || {});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { indicator } = resolveSchema(schema);
|
|
18
|
+
export function createStore(entity, schema, endpoints, options) {
|
|
19
|
+
const { indicator } = resolveSchema(schema, {
|
|
20
|
+
indicator: options?.indicator
|
|
21
|
+
});
|
|
24
22
|
let apiClient;
|
|
25
23
|
function api() {
|
|
26
24
|
if (!apiClient) {
|
|
27
25
|
const config = useRuntimeConfig();
|
|
28
26
|
apiClient = createApi({
|
|
29
|
-
...config.public.harlemify?.api,
|
|
27
|
+
...config.public.harlemify?.api ?? {},
|
|
30
28
|
...options?.api
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
return apiClient;
|
|
34
32
|
}
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
unit: null,
|
|
40
|
-
units: []
|
|
41
|
-
},
|
|
42
|
-
endpoints: {}
|
|
33
|
+
const state = {
|
|
34
|
+
memory: {
|
|
35
|
+
unit: null,
|
|
36
|
+
units: []
|
|
43
37
|
},
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const memorizedUnit = store.getter("memorizedUnit", (state) => {
|
|
49
|
-
return state.memory.unit;
|
|
38
|
+
endpoints: {}
|
|
39
|
+
};
|
|
40
|
+
const store = createHarlemStore(entity, state, {
|
|
41
|
+
extensions: options?.extensions ?? []
|
|
50
42
|
});
|
|
51
|
-
const
|
|
52
|
-
|
|
43
|
+
const alias = {
|
|
44
|
+
unit: entity,
|
|
45
|
+
units: pluralize(entity)
|
|
46
|
+
};
|
|
47
|
+
const memorizedUnit = store.getter("memorizedUnit", (state2) => {
|
|
48
|
+
return state2.memory.unit;
|
|
53
49
|
});
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const memorizedUnits = store.getter("memorizedUnits", (state2) => {
|
|
51
|
+
return state2.memory.units;
|
|
52
|
+
});
|
|
53
|
+
const setMemorizedUnit = store.mutation("setMemorizedUnit", (state2, unit = null) => {
|
|
54
|
+
state2.memory.unit = unit;
|
|
55
|
+
});
|
|
56
|
+
const setMemorizedUnits = store.mutation("setMemorizedUnits", (state2, units = []) => {
|
|
57
|
+
state2.memory.units = units;
|
|
58
|
+
});
|
|
59
|
+
const editMemorizedUnit = store.mutation("editMemorizedUnit", (state2, unit) => {
|
|
60
|
+
if (state2.memory.unit?.[indicator] === unit[indicator]) {
|
|
61
|
+
state2.memory.unit = defu(unit, state2.memory.unit);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const editMemorizedUnits = store.mutation("editMemorizedUnits", (state2, units) => {
|
|
56
65
|
for (const unit of units) {
|
|
57
|
-
const
|
|
66
|
+
const index = state2.memory.units.findIndex((memorizedUnit2) => {
|
|
58
67
|
return memorizedUnit2[indicator] === unit[indicator];
|
|
59
68
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return output;
|
|
63
|
-
}
|
|
64
|
-
const setMemorizedUnit = store.mutation(
|
|
65
|
-
"setMemorizedUnit",
|
|
66
|
-
(state, unit = null) => {
|
|
67
|
-
state.memory.unit = unit;
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
const setMemorizedUnits = store.mutation(
|
|
71
|
-
"setMemorizedUnits",
|
|
72
|
-
(state, units = []) => {
|
|
73
|
-
state.memory.units = units;
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
const editMemorizedUnit = store.mutation(
|
|
77
|
-
"editMemorizedUnit",
|
|
78
|
-
(state, unit) => {
|
|
79
|
-
if (state.memory.unit?.[indicator] === unit[indicator]) {
|
|
80
|
-
state.memory.unit = defu(unit, state.memory.unit);
|
|
69
|
+
if (index !== -1) {
|
|
70
|
+
state2.memory.units[index] = defu(unit, state2.memory.units[index]);
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
|
-
);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
});
|
|
74
|
+
const dropMemorizedUnit = store.mutation("dropMemorizedUnit", (state2, unit) => {
|
|
75
|
+
if (state2.memory.unit?.[indicator] === unit[indicator]) {
|
|
76
|
+
state2.memory.unit = null;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const dropMemorizedUnits = store.mutation("dropMemorizedUnits", (state2, units) => {
|
|
80
|
+
state2.memory.units = state2.memory.units.filter((memorizedUnit2) => {
|
|
87
81
|
for (const unit of units) {
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
-
});
|
|
91
|
-
if (index !== -1) {
|
|
92
|
-
state.memory.units[index] = defu(
|
|
93
|
-
unit,
|
|
94
|
-
state.memory.units[index]
|
|
95
|
-
);
|
|
82
|
+
if (memorizedUnit2[indicator] === unit[indicator]) {
|
|
83
|
+
return false;
|
|
96
84
|
}
|
|
97
85
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
const dropMemorizedUnits = store.mutation(
|
|
109
|
-
"dropMemorizedUnits",
|
|
110
|
-
(state, units) => {
|
|
111
|
-
state.memory.units = state.memory.units.filter((memorizedUnit2) => {
|
|
112
|
-
for (const unit of units) {
|
|
113
|
-
if (memorizedUnit2[indicator] === unit[indicator]) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const monitor = {};
|
|
90
|
+
for (const endpoint of Object.values(Endpoint)) {
|
|
91
|
+
for (const endpointStatus of Object.values(EndpointStatus)) {
|
|
92
|
+
const statusKey = makeEndpointStatusName(endpoint, endpointStatus);
|
|
93
|
+
monitor[statusKey] = store.getter(statusKey, (state2) => {
|
|
94
|
+
return state2.endpoints[endpoint] === endpointStatus;
|
|
118
95
|
});
|
|
119
96
|
}
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
key,
|
|
126
|
-
memory
|
|
127
|
-
}) => {
|
|
128
|
-
state.endpoints[key] = memory;
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
const purgeEndpointMemory = store.mutation(
|
|
132
|
-
"purgeEndpointMemory",
|
|
133
|
-
(state) => {
|
|
134
|
-
state.endpoints = {};
|
|
97
|
+
}
|
|
98
|
+
const patchMonitor = store.mutation(
|
|
99
|
+
"patchMonitor",
|
|
100
|
+
(state2, payload) => {
|
|
101
|
+
state2.endpoints[payload.endpoint] = payload.status;
|
|
135
102
|
}
|
|
136
103
|
);
|
|
137
|
-
function
|
|
138
|
-
if (
|
|
139
|
-
const statusKey =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
143
|
-
if (endpointsStatus[statusKey].value) {
|
|
144
|
-
throw new Error(`Endpoint "${key}" is already pending`);
|
|
104
|
+
function patchMonitorTo(endpoint, status) {
|
|
105
|
+
if (status === EndpointStatus.PENDING) {
|
|
106
|
+
const statusKey = makeEndpointStatusName(endpoint, EndpointStatus.PENDING);
|
|
107
|
+
if (monitor[statusKey].value) {
|
|
108
|
+
throw new Error(`Endpoint "${endpoint}" is already pending`);
|
|
145
109
|
}
|
|
146
110
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
111
|
+
patchMonitor({
|
|
112
|
+
endpoint,
|
|
113
|
+
status
|
|
150
114
|
});
|
|
151
115
|
}
|
|
152
|
-
async function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
status: EndpointStatus.PENDING
|
|
156
|
-
});
|
|
116
|
+
async function withStatus(key, operation) {
|
|
117
|
+
await options?.hooks?.before?.();
|
|
118
|
+
patchMonitorTo(key, EndpointStatus.PENDING);
|
|
157
119
|
try {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
setMemorizedUnit(response);
|
|
163
|
-
patchEndpointMemoryTo(Endpoint.GET_UNIT, {
|
|
164
|
-
status: EndpointStatus.SUCCESS
|
|
165
|
-
});
|
|
166
|
-
return response;
|
|
120
|
+
const result = await operation();
|
|
121
|
+
patchMonitorTo(key, EndpointStatus.SUCCESS);
|
|
122
|
+
await options?.hooks?.after?.();
|
|
123
|
+
return result;
|
|
167
124
|
} catch (error) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
125
|
+
patchMonitorTo(key, EndpointStatus.FAILED);
|
|
126
|
+
await options?.hooks?.after?.(error);
|
|
171
127
|
throw error;
|
|
172
128
|
}
|
|
173
129
|
}
|
|
174
|
-
async function
|
|
175
|
-
const endpoint = getEndpoint(endpoints, Endpoint.
|
|
176
|
-
|
|
177
|
-
|
|
130
|
+
async function getUnitEndpoint(unit, options2) {
|
|
131
|
+
const endpoint = getEndpoint(endpoints, Endpoint.GET_UNIT);
|
|
132
|
+
return withStatus(Endpoint.GET_UNIT, async () => {
|
|
133
|
+
const response = await api().get(resolveEndpointUrl(endpoint, unit), options2);
|
|
134
|
+
setMemorizedUnit(response);
|
|
135
|
+
return response;
|
|
178
136
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
);
|
|
137
|
+
}
|
|
138
|
+
async function getUnitsEndpoint(options2) {
|
|
139
|
+
const endpoint = getEndpoint(endpoints, Endpoint.GET_UNITS);
|
|
140
|
+
return withStatus(Endpoint.GET_UNITS, async () => {
|
|
141
|
+
const response = await api().get(resolveEndpointUrl(endpoint), options2);
|
|
184
142
|
setMemorizedUnits(response);
|
|
185
|
-
patchEndpointMemoryTo(Endpoint.GET_UNITS, {
|
|
186
|
-
status: EndpointStatus.SUCCESS
|
|
187
|
-
});
|
|
188
143
|
return response;
|
|
189
|
-
}
|
|
190
|
-
patchEndpointMemoryTo(Endpoint.GET_UNITS, {
|
|
191
|
-
status: EndpointStatus.FAILED
|
|
192
|
-
});
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
144
|
+
});
|
|
195
145
|
}
|
|
196
|
-
async function
|
|
146
|
+
async function postUnitEndpoint(unit, actionOptions) {
|
|
197
147
|
const endpoint = getEndpoint(endpoints, Endpoint.POST_UNIT);
|
|
198
|
-
const resolvedSchema = resolveSchema(schema, endpoint
|
|
199
|
-
if (
|
|
148
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
149
|
+
if (actionOptions?.validate) {
|
|
200
150
|
schema.pick(resolvedSchema.keys).parse(unit);
|
|
201
151
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const response = await api().post(
|
|
207
|
-
resolveEndpointUrl(endpoint, unit),
|
|
208
|
-
{
|
|
209
|
-
...options2,
|
|
210
|
-
body: options2?.body ?? resolvedSchema.values
|
|
211
|
-
}
|
|
212
|
-
);
|
|
213
|
-
setMemorizedUnit({
|
|
214
|
-
...unit,
|
|
215
|
-
...response
|
|
216
|
-
});
|
|
217
|
-
patchEndpointMemoryTo(Endpoint.POST_UNIT, {
|
|
218
|
-
status: EndpointStatus.SUCCESS
|
|
152
|
+
return withStatus(Endpoint.POST_UNIT, async () => {
|
|
153
|
+
const response = await api().post(resolveEndpointUrl(endpoint, unit), {
|
|
154
|
+
...actionOptions,
|
|
155
|
+
body: actionOptions?.body ?? resolvedSchema.values
|
|
219
156
|
});
|
|
157
|
+
setMemorizedUnit({ ...unit, ...response });
|
|
220
158
|
return response;
|
|
221
|
-
}
|
|
222
|
-
patchEndpointMemoryTo(Endpoint.POST_UNIT, {
|
|
223
|
-
status: EndpointStatus.FAILED
|
|
224
|
-
});
|
|
225
|
-
throw error;
|
|
226
|
-
}
|
|
159
|
+
});
|
|
227
160
|
}
|
|
228
|
-
async function
|
|
161
|
+
async function postUnitsEndpoint(units, options2) {
|
|
229
162
|
const endpoint = getEndpoint(endpoints, Endpoint.POST_UNITS);
|
|
230
|
-
|
|
231
|
-
status: EndpointStatus.PENDING
|
|
232
|
-
});
|
|
233
|
-
try {
|
|
163
|
+
return withStatus(Endpoint.POST_UNITS, async () => {
|
|
234
164
|
const responses = [];
|
|
235
165
|
for (const unit of units) {
|
|
236
|
-
const resolvedSchema = resolveSchema(
|
|
237
|
-
schema,
|
|
238
|
-
endpoint.action,
|
|
239
|
-
unit
|
|
240
|
-
);
|
|
166
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
241
167
|
if (options2?.validate) {
|
|
242
168
|
schema.pick(resolvedSchema.keys).parse(unit);
|
|
243
169
|
}
|
|
244
|
-
const response = await api().post(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
body: options2?.body ?? resolvedSchema.values
|
|
249
|
-
}
|
|
250
|
-
);
|
|
170
|
+
const response = await api().post(resolveEndpointUrl(endpoint, unit), {
|
|
171
|
+
...options2,
|
|
172
|
+
body: options2?.body ?? resolvedSchema.values
|
|
173
|
+
});
|
|
251
174
|
const clonedUnits = [...memorizedUnits.value];
|
|
252
175
|
if (options2?.position === "last" /* LAST */) {
|
|
253
|
-
clonedUnits.push({
|
|
254
|
-
...unit,
|
|
255
|
-
...response
|
|
256
|
-
});
|
|
176
|
+
clonedUnits.push({ ...unit, ...response });
|
|
257
177
|
} else {
|
|
258
|
-
clonedUnits.unshift({
|
|
259
|
-
...unit,
|
|
260
|
-
...response
|
|
261
|
-
});
|
|
178
|
+
clonedUnits.unshift({ ...unit, ...response });
|
|
262
179
|
}
|
|
263
180
|
setMemorizedUnits(clonedUnits);
|
|
264
181
|
responses.push(response);
|
|
265
182
|
}
|
|
266
|
-
patchEndpointMemoryTo(Endpoint.POST_UNITS, {
|
|
267
|
-
status: EndpointStatus.SUCCESS
|
|
268
|
-
});
|
|
269
183
|
return responses;
|
|
270
|
-
}
|
|
271
|
-
patchEndpointMemoryTo(Endpoint.POST_UNITS, {
|
|
272
|
-
status: EndpointStatus.FAILED
|
|
273
|
-
});
|
|
274
|
-
throw error;
|
|
275
|
-
}
|
|
184
|
+
});
|
|
276
185
|
}
|
|
277
|
-
async function
|
|
186
|
+
async function putUnitEndpoint(unit, options2) {
|
|
278
187
|
const endpoint = getEndpoint(endpoints, Endpoint.PUT_UNIT);
|
|
279
|
-
const resolvedSchema = resolveSchema(schema, endpoint
|
|
188
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
280
189
|
if (options2?.validate) {
|
|
281
190
|
schema.pick(resolvedSchema.keys).parse(unit);
|
|
282
191
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const response = await api().put(
|
|
288
|
-
resolveEndpointUrl(endpoint, unit),
|
|
289
|
-
{
|
|
290
|
-
...options2,
|
|
291
|
-
body: options2?.body ?? resolvedSchema.values
|
|
292
|
-
}
|
|
293
|
-
);
|
|
294
|
-
setMemorizedUnit({
|
|
295
|
-
...unit,
|
|
296
|
-
...response
|
|
297
|
-
});
|
|
298
|
-
patchEndpointMemoryTo(Endpoint.PUT_UNIT, {
|
|
299
|
-
status: EndpointStatus.SUCCESS
|
|
192
|
+
return withStatus(Endpoint.PUT_UNIT, async () => {
|
|
193
|
+
const response = await api().put(resolveEndpointUrl(endpoint, unit), {
|
|
194
|
+
...options2,
|
|
195
|
+
body: options2?.body ?? resolvedSchema.values
|
|
300
196
|
});
|
|
197
|
+
setMemorizedUnit({ ...unit, ...response });
|
|
301
198
|
return response;
|
|
302
|
-
}
|
|
303
|
-
patchEndpointMemoryTo(Endpoint.PUT_UNIT, {
|
|
304
|
-
status: EndpointStatus.FAILED
|
|
305
|
-
});
|
|
306
|
-
throw error;
|
|
307
|
-
}
|
|
199
|
+
});
|
|
308
200
|
}
|
|
309
|
-
async function
|
|
201
|
+
async function putUnitsEndpoint(units, options2) {
|
|
310
202
|
const endpoint = getEndpoint(endpoints, Endpoint.PUT_UNITS);
|
|
311
|
-
|
|
312
|
-
status: EndpointStatus.PENDING
|
|
313
|
-
});
|
|
314
|
-
try {
|
|
203
|
+
return withStatus(Endpoint.PUT_UNITS, async () => {
|
|
315
204
|
const responses = [];
|
|
316
205
|
for (const unit of units) {
|
|
317
|
-
const resolvedSchema = resolveSchema(
|
|
318
|
-
schema,
|
|
319
|
-
endpoint.action,
|
|
320
|
-
unit
|
|
321
|
-
);
|
|
206
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
322
207
|
if (options2?.validate) {
|
|
323
208
|
schema.pick(resolvedSchema.keys).parse(unit);
|
|
324
209
|
}
|
|
325
|
-
const response = await api().put(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
);
|
|
332
|
-
editMemorizedUnits([
|
|
333
|
-
{
|
|
334
|
-
...unit,
|
|
335
|
-
...response
|
|
336
|
-
}
|
|
337
|
-
]);
|
|
210
|
+
const response = await api().put(resolveEndpointUrl(endpoint, unit), {
|
|
211
|
+
...options2,
|
|
212
|
+
body: options2?.body ?? resolvedSchema.values
|
|
213
|
+
});
|
|
214
|
+
editMemorizedUnits([{ ...unit, ...response }]);
|
|
338
215
|
responses.push(response);
|
|
339
216
|
}
|
|
340
|
-
patchEndpointMemoryTo(Endpoint.PUT_UNITS, {
|
|
341
|
-
status: EndpointStatus.SUCCESS
|
|
342
|
-
});
|
|
343
217
|
return responses;
|
|
344
|
-
}
|
|
345
|
-
patchEndpointMemoryTo(Endpoint.PUT_UNITS, {
|
|
346
|
-
status: EndpointStatus.FAILED
|
|
347
|
-
});
|
|
348
|
-
throw error;
|
|
349
|
-
}
|
|
218
|
+
});
|
|
350
219
|
}
|
|
351
|
-
async function
|
|
220
|
+
async function patchUnitEndpoint(unit, options2) {
|
|
352
221
|
const endpoint = getEndpoint(endpoints, Endpoint.PATCH_UNIT);
|
|
353
|
-
const resolvedSchema = resolveSchema(schema, endpoint
|
|
222
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
354
223
|
if (options2?.validate) {
|
|
355
224
|
schema.pick(resolvedSchema.keys).partial().parse(unit);
|
|
356
225
|
}
|
|
357
|
-
|
|
358
|
-
status: EndpointStatus.PENDING
|
|
359
|
-
});
|
|
360
|
-
try {
|
|
226
|
+
return withStatus(Endpoint.PATCH_UNIT, async () => {
|
|
361
227
|
const response = await api().patch(resolveEndpointUrl(endpoint, unit), {
|
|
362
228
|
...options2,
|
|
363
229
|
body: options2?.body ?? resolvedSchema.values
|
|
364
230
|
});
|
|
365
|
-
editMemorizedUnit({
|
|
366
|
-
...unit,
|
|
367
|
-
...response
|
|
368
|
-
});
|
|
369
|
-
patchEndpointMemoryTo(Endpoint.PATCH_UNIT, {
|
|
370
|
-
status: EndpointStatus.SUCCESS
|
|
371
|
-
});
|
|
231
|
+
editMemorizedUnit({ ...unit, ...response });
|
|
372
232
|
return response;
|
|
373
|
-
}
|
|
374
|
-
patchEndpointMemoryTo(Endpoint.PATCH_UNIT, {
|
|
375
|
-
status: EndpointStatus.FAILED
|
|
376
|
-
});
|
|
377
|
-
throw error;
|
|
378
|
-
}
|
|
233
|
+
});
|
|
379
234
|
}
|
|
380
|
-
async function
|
|
235
|
+
async function patchUnitsEndpoint(units, options2) {
|
|
381
236
|
const endpoint = getEndpoint(endpoints, Endpoint.PATCH_UNITS);
|
|
382
|
-
|
|
383
|
-
status: EndpointStatus.PENDING
|
|
384
|
-
});
|
|
385
|
-
try {
|
|
237
|
+
return withStatus(Endpoint.PATCH_UNITS, async () => {
|
|
386
238
|
const responses = [];
|
|
387
239
|
for (const unit of units) {
|
|
388
|
-
const resolvedSchema = resolveSchema(
|
|
389
|
-
schema,
|
|
390
|
-
endpoint.action,
|
|
391
|
-
unit
|
|
392
|
-
);
|
|
240
|
+
const resolvedSchema = resolveSchema(schema, { indicator, endpoint, unit });
|
|
393
241
|
if (options2?.validate) {
|
|
394
242
|
schema.pick(resolvedSchema.keys).partial().parse(unit);
|
|
395
243
|
}
|
|
@@ -397,95 +245,56 @@ export function createStore(name, schema, endpoints, options) {
|
|
|
397
245
|
...options2,
|
|
398
246
|
body: options2?.body ?? resolvedSchema.values
|
|
399
247
|
});
|
|
400
|
-
editMemorizedUnits([
|
|
401
|
-
{
|
|
402
|
-
...unit,
|
|
403
|
-
...response
|
|
404
|
-
}
|
|
405
|
-
]);
|
|
248
|
+
editMemorizedUnits([{ ...unit, ...response }]);
|
|
406
249
|
responses.push(response);
|
|
407
250
|
}
|
|
408
|
-
patchEndpointMemoryTo(Endpoint.PATCH_UNITS, {
|
|
409
|
-
status: EndpointStatus.SUCCESS
|
|
410
|
-
});
|
|
411
251
|
return responses;
|
|
412
|
-
}
|
|
413
|
-
patchEndpointMemoryTo(Endpoint.PATCH_UNITS, {
|
|
414
|
-
status: EndpointStatus.FAILED
|
|
415
|
-
});
|
|
416
|
-
throw error;
|
|
417
|
-
}
|
|
252
|
+
});
|
|
418
253
|
}
|
|
419
|
-
async function
|
|
254
|
+
async function deleteUnitEndpoint(unit, options2) {
|
|
420
255
|
const endpoint = getEndpoint(endpoints, Endpoint.DELETE_UNIT);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
try {
|
|
425
|
-
await api().del(
|
|
426
|
-
resolveEndpointUrl(endpoint, unit),
|
|
427
|
-
options2
|
|
428
|
-
);
|
|
256
|
+
return withStatus(Endpoint.DELETE_UNIT, async () => {
|
|
257
|
+
await api().del(resolveEndpointUrl(endpoint, unit), options2);
|
|
429
258
|
dropMemorizedUnit(unit);
|
|
430
|
-
patchEndpointMemoryTo(Endpoint.DELETE_UNIT, {
|
|
431
|
-
status: EndpointStatus.SUCCESS
|
|
432
|
-
});
|
|
433
259
|
return true;
|
|
434
|
-
}
|
|
435
|
-
patchEndpointMemoryTo(Endpoint.DELETE_UNIT, {
|
|
436
|
-
status: EndpointStatus.FAILED
|
|
437
|
-
});
|
|
438
|
-
throw error;
|
|
439
|
-
}
|
|
260
|
+
});
|
|
440
261
|
}
|
|
441
|
-
async function
|
|
262
|
+
async function deleteUnitsEndpoint(units, options2) {
|
|
442
263
|
const endpoint = getEndpoint(endpoints, Endpoint.DELETE_UNITS);
|
|
443
|
-
|
|
444
|
-
status: EndpointStatus.PENDING
|
|
445
|
-
});
|
|
446
|
-
try {
|
|
264
|
+
return withStatus(Endpoint.DELETE_UNITS, async () => {
|
|
447
265
|
for (const unit of units) {
|
|
448
|
-
await api().del(
|
|
449
|
-
resolveEndpointUrl(endpoint, unit),
|
|
450
|
-
options2
|
|
451
|
-
);
|
|
266
|
+
await api().del(resolveEndpointUrl(endpoint, unit), options2);
|
|
452
267
|
dropMemorizedUnits([unit]);
|
|
453
268
|
}
|
|
454
|
-
patchEndpointMemoryTo(Endpoint.DELETE_UNITS, {
|
|
455
|
-
status: EndpointStatus.SUCCESS
|
|
456
|
-
});
|
|
457
269
|
return true;
|
|
458
|
-
}
|
|
459
|
-
patchEndpointMemoryTo(Endpoint.DELETE_UNITS, {
|
|
460
|
-
status: EndpointStatus.FAILED
|
|
461
|
-
});
|
|
462
|
-
throw error;
|
|
463
|
-
}
|
|
270
|
+
});
|
|
464
271
|
}
|
|
465
272
|
return {
|
|
466
|
-
api,
|
|
467
273
|
store,
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
274
|
+
alias,
|
|
275
|
+
indicator,
|
|
276
|
+
unit: memorizedUnit,
|
|
277
|
+
units: memorizedUnits,
|
|
278
|
+
memory: {
|
|
279
|
+
setUnit: setMemorizedUnit,
|
|
280
|
+
setUnits: setMemorizedUnits,
|
|
281
|
+
editUnit: editMemorizedUnit,
|
|
282
|
+
editUnits: editMemorizedUnits,
|
|
283
|
+
dropUnit: dropMemorizedUnit,
|
|
284
|
+
dropUnits: dropMemorizedUnits
|
|
285
|
+
},
|
|
286
|
+
endpoint: {
|
|
287
|
+
getUnit: getUnitEndpoint,
|
|
288
|
+
getUnits: getUnitsEndpoint,
|
|
289
|
+
postUnit: postUnitEndpoint,
|
|
290
|
+
postUnits: postUnitsEndpoint,
|
|
291
|
+
putUnit: putUnitEndpoint,
|
|
292
|
+
putUnits: putUnitsEndpoint,
|
|
293
|
+
patchUnit: patchUnitEndpoint,
|
|
294
|
+
patchUnits: patchUnitsEndpoint,
|
|
295
|
+
deleteUnit: deleteUnitEndpoint,
|
|
296
|
+
deleteUnits: deleteUnitsEndpoint
|
|
297
|
+
},
|
|
298
|
+
monitor
|
|
490
299
|
};
|
|
491
300
|
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { type SchemaMeta, getMeta, resolveSchema } from "./utils/schema.js";
|
|
1
|
+
export { EndpointMethod, Endpoint, EndpointStatus } from "./utils/endpoint.js";
|
|
2
|
+
export { getMeta, resolveSchema } from "./utils/schema.js";
|
|
3
|
+
export { createApi, ApiResponseType, ApiErrorSource, ApiError, ApiRequestError, ApiResponseError } from "./core/api.js";
|
|
5
4
|
export { createStore, StoreMemoryPosition } from "./core/store.js";
|
|
5
|
+
export { useStoreAlias } from "./composables/use.js";
|
|
6
|
+
export type { EndpointDefinition } from "./utils/endpoint.js";
|
|
7
|
+
export type { SchemaMeta } from "./utils/schema.js";
|
|
8
|
+
export type { ApiRequestHeader, ApiRequestQuery, ApiRequestBody, ApiRequestOptions, ApiOptions, EndpointMethodOptions, ApiErrorOptions, } from "./core/api.js";
|