@htlkg/data 0.0.1 → 0.0.3
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 +53 -0
- package/dist/client/index.d.ts +117 -31
- package/dist/client/index.js +74 -22
- package/dist/client/index.js.map +1 -1
- package/dist/content-collections/index.js +20 -24
- package/dist/content-collections/index.js.map +1 -1
- package/dist/hooks/index.d.ts +113 -5
- package/dist/hooks/index.js +165 -182
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +305 -182
- package/dist/index.js.map +1 -1
- package/dist/queries/index.d.ts +78 -1
- package/dist/queries/index.js +47 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/stores/index.d.ts +106 -0
- package/dist/stores/index.js +108 -0
- package/dist/stores/index.js.map +1 -0
- package/package.json +60 -37
- package/src/client/__tests__/server.test.ts +100 -0
- package/src/client/client.md +91 -0
- package/src/client/index.test.ts +232 -0
- package/src/client/index.ts +145 -0
- package/src/client/server.ts +118 -0
- package/src/content-collections/content-collections.md +87 -0
- package/src/content-collections/generator.ts +314 -0
- package/src/content-collections/index.ts +32 -0
- package/src/content-collections/schemas.ts +75 -0
- package/src/content-collections/sync.ts +139 -0
- package/src/hooks/README.md +293 -0
- package/src/hooks/createDataHook.ts +208 -0
- package/src/hooks/data-hook-errors.property.test.ts +270 -0
- package/src/hooks/data-hook-filters.property.test.ts +263 -0
- package/src/hooks/data-hooks.property.test.ts +190 -0
- package/src/hooks/hooks.test.ts +76 -0
- package/src/hooks/index.ts +21 -0
- package/src/hooks/useAccounts.ts +66 -0
- package/src/hooks/useBrands.ts +95 -0
- package/src/hooks/useProducts.ts +88 -0
- package/src/hooks/useUsers.ts +89 -0
- package/src/index.ts +32 -0
- package/src/mutations/accounts.ts +127 -0
- package/src/mutations/brands.ts +133 -0
- package/src/mutations/index.ts +32 -0
- package/src/mutations/mutations.md +96 -0
- package/src/mutations/users.ts +136 -0
- package/src/queries/accounts.ts +121 -0
- package/src/queries/brands.ts +176 -0
- package/src/queries/index.ts +45 -0
- package/src/queries/products.ts +282 -0
- package/src/queries/queries.md +88 -0
- package/src/queries/server-helpers.ts +114 -0
- package/src/queries/users.ts +199 -0
- package/src/stores/createStores.ts +148 -0
- package/src/stores/index.ts +15 -0
- package/src/stores/stores.md +104 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export { AstroAmplifyConfig, generateClient, generateServerClient } from './client/index.js';
|
|
2
|
-
export { getAccount, getAccountWithBrands, getBrand, getBrandWithProducts, getProduct, getProductInstance, getUser, getUserByCognitoId, getUserByEmail, listAccounts, listActiveBrands, listActiveProducts, listActiveUsers, listBrands, listBrandsByAccount, listEnabledProductInstancesByBrand, listProductInstancesByAccount, listProductInstancesByBrand, listProducts, listUsers, listUsersByAccount } from './queries/index.js';
|
|
1
|
+
export { AstroAmplifyConfig, generateClient, generateServerClient, getSharedClient, resetSharedClient as resetClientInstance, resetSharedClient } from './client/index.js';
|
|
2
|
+
export { executePublicQuery, executeServerQuery, getAccount, getAccountWithBrands, getBrand, getBrandWithProducts, getProduct, getProductInstance, getUser, getUserByCognitoId, getUserByEmail, listAccounts, listActiveBrands, listActiveProducts, listActiveUsers, listBrands, listBrandsByAccount, listEnabledProductInstancesByBrand, listProductInstancesByAccount, listProductInstancesByBrand, listProducts, listUsers, listUsersByAccount } from './queries/index.js';
|
|
3
3
|
export { CreateAccountInput, CreateBrandInput, CreateUserInput, UpdateAccountInput, UpdateBrandInput, UpdateUserInput, createAccount, createBrand, createUser, deleteAccount, deleteBrand, deleteUser, updateAccount, updateBrand, updateUser } from './mutations/index.js';
|
|
4
|
-
export { UseAccountsOptions, UseAccountsReturn, UseBrandsOptions, UseBrandsReturn, UseProductsOptions, UseProductsReturn, UseUsersOptions, UseUsersReturn, useAccounts, useBrands, useProducts, useUsers } from './hooks/index.js';
|
|
5
|
-
|
|
4
|
+
export { BaseHookOptions, CreateDataHookOptions, DataHookReturn, InferHookReturn, UseAccountsOptions, UseAccountsReturn, UseBrandsOptions, UseBrandsReturn, UseProductsOptions, UseProductsReturn, UseUsersOptions, UseUsersReturn, createDataHook, useAccounts, useBrands, useProducts, useUsers } from './hooks/index.js';
|
|
5
|
+
export { InferStoreType, ResourceStores, StoreConfig, createResourceStores, createSingleStore, createStore } from './stores/index.js';
|
|
6
6
|
import 'aws-amplify/data';
|
|
7
|
+
import 'aws-amplify';
|
|
8
|
+
import 'astro';
|
|
9
|
+
import 'aws-amplify/api/internals';
|
|
7
10
|
import '@htlkg/core/types';
|
|
8
11
|
import 'vue';
|
|
12
|
+
import 'nanostores';
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
1
|
+
// src/client/index.ts
|
|
2
|
+
import { generateClient as generateDataClient } from "aws-amplify/data";
|
|
14
3
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
// src/client/server.ts
|
|
5
|
+
import {
|
|
6
|
+
generateClientWithAmplifyInstance
|
|
7
|
+
} from "aws-amplify/api/internals";
|
|
8
|
+
import { getAmplifyServerContext } from "aws-amplify/adapter-core/internals";
|
|
9
|
+
import { createRunWithAmplifyServerContext, createLogger } from "@htlkg/core/amplify-astro-adapter";
|
|
10
|
+
var log = createLogger("server-client");
|
|
19
11
|
|
|
20
12
|
// src/client/index.ts
|
|
13
|
+
var sharedClientInstance = null;
|
|
14
|
+
function getSharedClient() {
|
|
15
|
+
if (!sharedClientInstance) {
|
|
16
|
+
sharedClientInstance = generateDataClient();
|
|
17
|
+
}
|
|
18
|
+
return sharedClientInstance;
|
|
19
|
+
}
|
|
20
|
+
function resetSharedClient() {
|
|
21
|
+
sharedClientInstance = null;
|
|
22
|
+
}
|
|
21
23
|
function generateClient() {
|
|
22
|
-
return (
|
|
24
|
+
return generateDataClient();
|
|
23
25
|
}
|
|
24
26
|
function generateServerClient(options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
27
|
+
const client = generateDataClient();
|
|
28
|
+
return client;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
// src/queries/brands.ts
|
|
@@ -356,6 +357,34 @@ async function listEnabledProductInstancesByBrand(client, brandId, options) {
|
|
|
356
357
|
}
|
|
357
358
|
}
|
|
358
359
|
|
|
360
|
+
// src/queries/server-helpers.ts
|
|
361
|
+
async function executeServerQuery(astro, runWithAmplifyServerContext, operation) {
|
|
362
|
+
const result = await runWithAmplifyServerContext({
|
|
363
|
+
astroServerContext: {
|
|
364
|
+
cookies: astro.cookies,
|
|
365
|
+
request: astro.request
|
|
366
|
+
},
|
|
367
|
+
operation: async (contextSpec) => {
|
|
368
|
+
const client = generateServerClient();
|
|
369
|
+
return await operation(client);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
async function executePublicQuery(astro, runWithAmplifyServerContext, operation) {
|
|
375
|
+
const result = await runWithAmplifyServerContext({
|
|
376
|
+
astroServerContext: {
|
|
377
|
+
cookies: astro.cookies,
|
|
378
|
+
request: astro.request
|
|
379
|
+
},
|
|
380
|
+
operation: async (_contextSpec) => {
|
|
381
|
+
const client = generateServerClient({ authMode: "apiKey" });
|
|
382
|
+
return await operation(client);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
|
|
359
388
|
// src/mutations/brands.ts
|
|
360
389
|
async function createBrand(client, input) {
|
|
361
390
|
try {
|
|
@@ -479,204 +508,295 @@ async function deleteUser(client, id) {
|
|
|
479
508
|
}
|
|
480
509
|
}
|
|
481
510
|
|
|
482
|
-
// src/hooks/
|
|
511
|
+
// src/hooks/createDataHook.ts
|
|
483
512
|
import { ref, computed, onMounted } from "vue";
|
|
484
|
-
function
|
|
513
|
+
function createDataHook(config) {
|
|
485
514
|
const {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
515
|
+
model,
|
|
516
|
+
defaultLimit,
|
|
517
|
+
selectionSet,
|
|
518
|
+
transform,
|
|
519
|
+
buildFilter: buildFilter4,
|
|
520
|
+
computedProperties,
|
|
521
|
+
dataPropertyName = "data"
|
|
522
|
+
} = config;
|
|
523
|
+
return function useData(options = {}) {
|
|
524
|
+
const { filter: baseFilter, limit = defaultLimit, autoFetch = true } = options;
|
|
525
|
+
const data = ref([]);
|
|
526
|
+
const loading = ref(false);
|
|
527
|
+
const error = ref(null);
|
|
528
|
+
const getFilter = () => {
|
|
529
|
+
if (buildFilter4) {
|
|
530
|
+
return buildFilter4(options);
|
|
531
|
+
}
|
|
532
|
+
return baseFilter && Object.keys(baseFilter).length > 0 ? baseFilter : void 0;
|
|
533
|
+
};
|
|
534
|
+
async function fetch() {
|
|
535
|
+
loading.value = true;
|
|
536
|
+
error.value = null;
|
|
537
|
+
try {
|
|
538
|
+
const client = getSharedClient();
|
|
539
|
+
const queryOptions = {
|
|
540
|
+
filter: getFilter(),
|
|
541
|
+
limit
|
|
542
|
+
};
|
|
543
|
+
if (selectionSet) {
|
|
544
|
+
queryOptions.selectionSet = selectionSet;
|
|
545
|
+
}
|
|
546
|
+
const { data: responseData, errors } = await client.models[model].list(queryOptions);
|
|
547
|
+
if (errors) {
|
|
548
|
+
throw new Error(errors[0]?.message || `Failed to fetch ${model}`);
|
|
549
|
+
}
|
|
550
|
+
const items = responseData || [];
|
|
551
|
+
data.value = transform ? items.map(transform) : items;
|
|
552
|
+
} catch (e) {
|
|
553
|
+
error.value = e;
|
|
554
|
+
console.error(`[use${model}] Error fetching ${model}:`, e);
|
|
555
|
+
} finally {
|
|
556
|
+
loading.value = false;
|
|
516
557
|
}
|
|
517
|
-
brands.value = data || [];
|
|
518
|
-
} catch (e) {
|
|
519
|
-
error.value = e;
|
|
520
|
-
console.error("[useBrands] Error fetching brands:", e);
|
|
521
|
-
} finally {
|
|
522
|
-
loading.value = false;
|
|
523
558
|
}
|
|
559
|
+
const computedRefs = {};
|
|
560
|
+
if (computedProperties) {
|
|
561
|
+
for (const [key, fn] of Object.entries(computedProperties)) {
|
|
562
|
+
computedRefs[key] = computed(() => fn(data.value));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (autoFetch) {
|
|
566
|
+
onMounted(() => {
|
|
567
|
+
fetch();
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const result = {
|
|
571
|
+
data,
|
|
572
|
+
loading,
|
|
573
|
+
error,
|
|
574
|
+
refetch: fetch,
|
|
575
|
+
computed: computedRefs
|
|
576
|
+
};
|
|
577
|
+
if (dataPropertyName !== "data") {
|
|
578
|
+
result[dataPropertyName] = data;
|
|
579
|
+
}
|
|
580
|
+
for (const [key, computedRef] of Object.entries(computedRefs)) {
|
|
581
|
+
result[key] = computedRef;
|
|
582
|
+
}
|
|
583
|
+
return result;
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/hooks/useBrands.ts
|
|
588
|
+
function buildFilter(options) {
|
|
589
|
+
let filter = options.filter || {};
|
|
590
|
+
if (options.accountId) {
|
|
591
|
+
filter = { ...filter, accountId: { eq: options.accountId } };
|
|
524
592
|
}
|
|
525
|
-
if (
|
|
526
|
-
|
|
527
|
-
fetch();
|
|
528
|
-
});
|
|
593
|
+
if (options.activeOnly) {
|
|
594
|
+
filter = { ...filter, status: { eq: "active" } };
|
|
529
595
|
}
|
|
596
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
597
|
+
}
|
|
598
|
+
var useBrandsInternal = createDataHook({
|
|
599
|
+
model: "Brand",
|
|
600
|
+
dataPropertyName: "brands",
|
|
601
|
+
buildFilter,
|
|
602
|
+
computedProperties: {
|
|
603
|
+
activeBrands: (brands) => brands.filter((b) => b.status === "active")
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
function useBrands(options = {}) {
|
|
607
|
+
const result = useBrandsInternal(options);
|
|
530
608
|
return {
|
|
531
|
-
brands,
|
|
532
|
-
activeBrands,
|
|
533
|
-
loading,
|
|
534
|
-
error,
|
|
535
|
-
refetch:
|
|
609
|
+
brands: result.brands,
|
|
610
|
+
activeBrands: result.activeBrands,
|
|
611
|
+
loading: result.loading,
|
|
612
|
+
error: result.error,
|
|
613
|
+
refetch: result.refetch
|
|
536
614
|
};
|
|
537
615
|
}
|
|
538
616
|
|
|
539
617
|
// src/hooks/useAccounts.ts
|
|
540
|
-
|
|
618
|
+
var useAccountsInternal = createDataHook({
|
|
619
|
+
model: "Account",
|
|
620
|
+
dataPropertyName: "accounts"
|
|
621
|
+
});
|
|
541
622
|
function useAccounts(options = {}) {
|
|
542
|
-
const
|
|
543
|
-
const accounts = ref2([]);
|
|
544
|
-
const loading = ref2(false);
|
|
545
|
-
const error = ref2(null);
|
|
546
|
-
async function fetch() {
|
|
547
|
-
loading.value = true;
|
|
548
|
-
error.value = null;
|
|
549
|
-
try {
|
|
550
|
-
const client = generateClient();
|
|
551
|
-
const { data, errors } = await client.models.Account.list({
|
|
552
|
-
filter,
|
|
553
|
-
limit
|
|
554
|
-
});
|
|
555
|
-
if (errors) {
|
|
556
|
-
throw new Error(errors[0]?.message || "Failed to fetch accounts");
|
|
557
|
-
}
|
|
558
|
-
accounts.value = data || [];
|
|
559
|
-
} catch (e) {
|
|
560
|
-
error.value = e;
|
|
561
|
-
console.error("[useAccounts] Error fetching accounts:", e);
|
|
562
|
-
} finally {
|
|
563
|
-
loading.value = false;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
if (autoFetch) {
|
|
567
|
-
onMounted2(() => {
|
|
568
|
-
fetch();
|
|
569
|
-
});
|
|
570
|
-
}
|
|
623
|
+
const result = useAccountsInternal(options);
|
|
571
624
|
return {
|
|
572
|
-
accounts,
|
|
573
|
-
loading,
|
|
574
|
-
error,
|
|
575
|
-
refetch:
|
|
625
|
+
accounts: result.accounts,
|
|
626
|
+
loading: result.loading,
|
|
627
|
+
error: result.error,
|
|
628
|
+
refetch: result.refetch
|
|
576
629
|
};
|
|
577
630
|
}
|
|
578
631
|
|
|
579
632
|
// src/hooks/useUsers.ts
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
const loading = ref3(false);
|
|
585
|
-
const error = ref3(null);
|
|
586
|
-
let filter = baseFilter || {};
|
|
587
|
-
if (brandId) {
|
|
588
|
-
filter = { ...filter, brandIds: { contains: brandId } };
|
|
589
|
-
}
|
|
590
|
-
if (accountId) {
|
|
591
|
-
filter = { ...filter, accountIds: { contains: accountId } };
|
|
592
|
-
}
|
|
593
|
-
async function fetch() {
|
|
594
|
-
loading.value = true;
|
|
595
|
-
error.value = null;
|
|
596
|
-
try {
|
|
597
|
-
const client = generateClient();
|
|
598
|
-
const { data, errors } = await client.models.User.list({
|
|
599
|
-
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
600
|
-
limit
|
|
601
|
-
});
|
|
602
|
-
if (errors) {
|
|
603
|
-
throw new Error(errors[0]?.message || "Failed to fetch users");
|
|
604
|
-
}
|
|
605
|
-
users.value = data || [];
|
|
606
|
-
} catch (e) {
|
|
607
|
-
error.value = e;
|
|
608
|
-
console.error("[useUsers] Error fetching users:", e);
|
|
609
|
-
} finally {
|
|
610
|
-
loading.value = false;
|
|
611
|
-
}
|
|
633
|
+
function buildFilter2(options) {
|
|
634
|
+
let filter = options.filter || {};
|
|
635
|
+
if (options.brandId) {
|
|
636
|
+
filter = { ...filter, brandIds: { contains: options.brandId } };
|
|
612
637
|
}
|
|
613
|
-
if (
|
|
614
|
-
|
|
615
|
-
fetch();
|
|
616
|
-
});
|
|
638
|
+
if (options.accountId) {
|
|
639
|
+
filter = { ...filter, accountIds: { contains: options.accountId } };
|
|
617
640
|
}
|
|
641
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
642
|
+
}
|
|
643
|
+
var useUsersInternal = createDataHook({
|
|
644
|
+
model: "User",
|
|
645
|
+
dataPropertyName: "users",
|
|
646
|
+
buildFilter: buildFilter2
|
|
647
|
+
});
|
|
648
|
+
function useUsers(options = {}) {
|
|
649
|
+
const result = useUsersInternal(options);
|
|
618
650
|
return {
|
|
619
|
-
users,
|
|
620
|
-
loading,
|
|
621
|
-
error,
|
|
622
|
-
refetch:
|
|
651
|
+
users: result.users,
|
|
652
|
+
loading: result.loading,
|
|
653
|
+
error: result.error,
|
|
654
|
+
refetch: result.refetch
|
|
623
655
|
};
|
|
624
656
|
}
|
|
625
657
|
|
|
626
658
|
// src/hooks/useProducts.ts
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const products = ref4([]);
|
|
631
|
-
const loading = ref4(false);
|
|
632
|
-
const error = ref4(null);
|
|
633
|
-
let filter = baseFilter || {};
|
|
634
|
-
if (activeOnly) {
|
|
659
|
+
function buildFilter3(options) {
|
|
660
|
+
let filter = options.filter || {};
|
|
661
|
+
if (options.activeOnly) {
|
|
635
662
|
filter = { ...filter, isActive: { eq: true } };
|
|
636
663
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const { data, errors } = await client.models.Product.list({
|
|
646
|
-
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
647
|
-
limit
|
|
648
|
-
});
|
|
649
|
-
if (errors) {
|
|
650
|
-
throw new Error(errors[0]?.message || "Failed to fetch products");
|
|
651
|
-
}
|
|
652
|
-
products.value = data || [];
|
|
653
|
-
} catch (e) {
|
|
654
|
-
error.value = e;
|
|
655
|
-
console.error("[useProducts] Error fetching products:", e);
|
|
656
|
-
} finally {
|
|
657
|
-
loading.value = false;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
if (autoFetch) {
|
|
661
|
-
onMounted4(() => {
|
|
662
|
-
fetch();
|
|
663
|
-
});
|
|
664
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
665
|
+
}
|
|
666
|
+
var useProductsInternal = createDataHook({
|
|
667
|
+
model: "Product",
|
|
668
|
+
dataPropertyName: "products",
|
|
669
|
+
buildFilter: buildFilter3,
|
|
670
|
+
computedProperties: {
|
|
671
|
+
activeProducts: (products) => products.filter((p) => p.isActive === true)
|
|
664
672
|
}
|
|
673
|
+
});
|
|
674
|
+
function useProducts(options = {}) {
|
|
675
|
+
const result = useProductsInternal(options);
|
|
665
676
|
return {
|
|
666
|
-
products,
|
|
667
|
-
activeProducts,
|
|
668
|
-
loading,
|
|
669
|
-
error,
|
|
670
|
-
refetch:
|
|
677
|
+
products: result.products,
|
|
678
|
+
activeProducts: result.activeProducts,
|
|
679
|
+
loading: result.loading,
|
|
680
|
+
error: result.error,
|
|
681
|
+
refetch: result.refetch
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/clean-stores/index.js
|
|
686
|
+
var clean = /* @__PURE__ */ Symbol("clean");
|
|
687
|
+
|
|
688
|
+
// ../../node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/atom/index.js
|
|
689
|
+
var listenerQueue = [];
|
|
690
|
+
var lqIndex = 0;
|
|
691
|
+
var QUEUE_ITEMS_PER_LISTENER = 4;
|
|
692
|
+
var epoch = 0;
|
|
693
|
+
var atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
|
|
694
|
+
let listeners = [];
|
|
695
|
+
let $atom = {
|
|
696
|
+
get() {
|
|
697
|
+
if (!$atom.lc) {
|
|
698
|
+
$atom.listen(() => {
|
|
699
|
+
})();
|
|
700
|
+
}
|
|
701
|
+
return $atom.value;
|
|
702
|
+
},
|
|
703
|
+
lc: 0,
|
|
704
|
+
listen(listener) {
|
|
705
|
+
$atom.lc = listeners.push(listener);
|
|
706
|
+
return () => {
|
|
707
|
+
for (let i = lqIndex + QUEUE_ITEMS_PER_LISTENER; i < listenerQueue.length; ) {
|
|
708
|
+
if (listenerQueue[i] === listener) {
|
|
709
|
+
listenerQueue.splice(i, QUEUE_ITEMS_PER_LISTENER);
|
|
710
|
+
} else {
|
|
711
|
+
i += QUEUE_ITEMS_PER_LISTENER;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
let index = listeners.indexOf(listener);
|
|
715
|
+
if (~index) {
|
|
716
|
+
listeners.splice(index, 1);
|
|
717
|
+
if (!--$atom.lc) $atom.off();
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
},
|
|
721
|
+
notify(oldValue, changedKey) {
|
|
722
|
+
epoch++;
|
|
723
|
+
let runListenerQueue = !listenerQueue.length;
|
|
724
|
+
for (let listener of listeners) {
|
|
725
|
+
listenerQueue.push(listener, $atom.value, oldValue, changedKey);
|
|
726
|
+
}
|
|
727
|
+
if (runListenerQueue) {
|
|
728
|
+
for (lqIndex = 0; lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) {
|
|
729
|
+
listenerQueue[lqIndex](
|
|
730
|
+
listenerQueue[lqIndex + 1],
|
|
731
|
+
listenerQueue[lqIndex + 2],
|
|
732
|
+
listenerQueue[lqIndex + 3]
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
listenerQueue.length = 0;
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
/* It will be called on last listener unsubscribing.
|
|
739
|
+
We will redefine it in onMount and onStop. */
|
|
740
|
+
off() {
|
|
741
|
+
},
|
|
742
|
+
set(newValue) {
|
|
743
|
+
let oldValue = $atom.value;
|
|
744
|
+
if (oldValue !== newValue) {
|
|
745
|
+
$atom.value = newValue;
|
|
746
|
+
$atom.notify(oldValue);
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
subscribe(listener) {
|
|
750
|
+
let unbind = $atom.listen(listener);
|
|
751
|
+
listener($atom.value);
|
|
752
|
+
return unbind;
|
|
753
|
+
},
|
|
754
|
+
value: initialValue
|
|
671
755
|
};
|
|
756
|
+
if (process.env.NODE_ENV !== "production") {
|
|
757
|
+
$atom[clean] = () => {
|
|
758
|
+
listeners = [];
|
|
759
|
+
$atom.lc = 0;
|
|
760
|
+
$atom.off();
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
return $atom;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
// src/stores/createStores.ts
|
|
767
|
+
function capitalize(str) {
|
|
768
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
769
|
+
}
|
|
770
|
+
function createResourceStores(shared, config) {
|
|
771
|
+
const { name, relations = [] } = config;
|
|
772
|
+
const stores = {};
|
|
773
|
+
stores.$data = shared(name, atom([]));
|
|
774
|
+
for (const relation of relations) {
|
|
775
|
+
const storeKey = `$${relation}`;
|
|
776
|
+
const sharedKey = `${name}${capitalize(relation)}`;
|
|
777
|
+
stores[storeKey] = shared(sharedKey, atom([]));
|
|
778
|
+
}
|
|
779
|
+
return stores;
|
|
780
|
+
}
|
|
781
|
+
function createStore(shared, name, defaultValue = []) {
|
|
782
|
+
return shared(name, atom(defaultValue));
|
|
783
|
+
}
|
|
784
|
+
function createSingleStore(shared, name, defaultValue) {
|
|
785
|
+
return shared(name, atom(defaultValue));
|
|
672
786
|
}
|
|
673
787
|
export {
|
|
674
788
|
createAccount,
|
|
675
789
|
createBrand,
|
|
790
|
+
createDataHook,
|
|
791
|
+
createResourceStores,
|
|
792
|
+
createSingleStore,
|
|
793
|
+
createStore,
|
|
676
794
|
createUser,
|
|
677
795
|
deleteAccount,
|
|
678
796
|
deleteBrand,
|
|
679
797
|
deleteUser,
|
|
798
|
+
executePublicQuery,
|
|
799
|
+
executeServerQuery,
|
|
680
800
|
generateClient,
|
|
681
801
|
generateServerClient,
|
|
682
802
|
getAccount,
|
|
@@ -685,6 +805,7 @@ export {
|
|
|
685
805
|
getBrandWithProducts,
|
|
686
806
|
getProduct,
|
|
687
807
|
getProductInstance,
|
|
808
|
+
getSharedClient,
|
|
688
809
|
getUser,
|
|
689
810
|
getUserByCognitoId,
|
|
690
811
|
getUserByEmail,
|
|
@@ -700,6 +821,8 @@ export {
|
|
|
700
821
|
listProducts,
|
|
701
822
|
listUsers,
|
|
702
823
|
listUsersByAccount,
|
|
824
|
+
resetSharedClient as resetClientInstance,
|
|
825
|
+
resetSharedClient,
|
|
703
826
|
updateAccount,
|
|
704
827
|
updateBrand,
|
|
705
828
|
updateUser,
|