@brytdesigns/shopify-utils 1.2.22 → 3.1.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/dist/effect/Actions/bridge.js +71 -0
- package/dist/effect/Actions/bridge.js.map +1 -0
- package/dist/effect/Actions/errors.js +46 -0
- package/dist/effect/Actions/errors.js.map +1 -0
- package/dist/effect/Actions/index.js +23 -0
- package/dist/effect/Actions/index.js.map +1 -0
- package/dist/effect/Actions/service.js +127 -0
- package/dist/effect/Actions/service.js.map +1 -0
- package/dist/effect/Actions/trampoline.js +26 -0
- package/dist/effect/Actions/trampoline.js.map +1 -0
- package/dist/effect/Ajax/Sections/index.js +2 -4
- package/dist/effect/Ajax/Sections/schema.js +28 -39
- package/dist/effect/Ajax/Sections/schema.js.map +1 -1
- package/dist/effect/Ajax/Window/data/AllowedRouteOrigins.js +75 -0
- package/dist/effect/Ajax/Window/data/AllowedRouteOrigins.js.map +1 -0
- package/dist/effect/Ajax/Window/data/ShopifyRoutes.js +86 -37
- package/dist/effect/Ajax/Window/data/ShopifyRoutes.js.map +1 -1
- package/dist/effect/Ajax/Window/data/StorefrontClientConfig.js +14 -13
- package/dist/effect/Ajax/Window/data/StorefrontClientConfig.js.map +1 -1
- package/dist/effect/Ajax/Window/data/StorefrontOrigin.js +32 -0
- package/dist/effect/Ajax/Window/data/StorefrontOrigin.js.map +1 -0
- package/dist/effect/Ajax/Window/data/index.js +15 -5
- package/dist/effect/Ajax/Window/data/index.js.map +1 -1
- package/dist/effect/Ajax/Window/index.js +2 -4
- package/dist/effect/Ajax/index.js +13 -3
- package/dist/effect/Ajax/index.js.map +1 -1
- package/dist/effect/Logging/index.js +13 -10
- package/dist/effect/Logging/index.js.map +1 -1
- package/dist/effect/Resource/data.js +20 -30
- package/dist/effect/Resource/data.js.map +1 -1
- package/dist/effect/Resource/index.js +14 -3
- package/dist/effect/Resource/index.js.map +1 -1
- package/dist/effect/Resource/schema.js +46 -45
- package/dist/effect/Resource/schema.js.map +1 -1
- package/dist/effect/Schemas/index.js +75 -0
- package/dist/effect/Schemas/index.js.map +1 -0
- package/dist/effect/_virtual/_rolldown/runtime.js +13 -0
- package/dist/effect/index.d.ts +396 -62
- package/dist/effect/index.js +6 -8
- package/dist/main/_virtual/_rolldown/runtime.js +13 -0
- package/dist/main/actions.js +78 -0
- package/dist/main/actions.js.map +1 -0
- package/dist/main/effect/Actions/bridge.js +65 -0
- package/dist/main/effect/Actions/bridge.js.map +1 -0
- package/dist/main/effect/Actions/errors.js +46 -0
- package/dist/main/effect/Actions/errors.js.map +1 -0
- package/dist/main/effect/Actions/index.js +4 -0
- package/dist/main/effect/Actions/service.js +127 -0
- package/dist/main/effect/Actions/service.js.map +1 -0
- package/dist/main/effect/Actions/trampoline.js +26 -0
- package/dist/main/effect/Actions/trampoline.js.map +1 -0
- package/dist/main/effect/Ajax/Sections/index.js +1 -4
- package/dist/main/effect/Ajax/Sections/schema.js +11 -41
- package/dist/main/effect/Ajax/Sections/schema.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/AllowedRouteOrigins.js +18 -0
- package/dist/main/effect/Ajax/Window/data/AllowedRouteOrigins.js.map +1 -0
- package/dist/main/effect/Ajax/Window/data/ShopifyRoutes.js +37 -37
- package/dist/main/effect/Ajax/Window/data/ShopifyRoutes.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/StorefrontClientConfig.js +3 -14
- package/dist/main/effect/Ajax/Window/data/StorefrontClientConfig.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/StorefrontOrigin.js +6 -0
- package/dist/main/effect/Ajax/Window/data/StorefrontOrigin.js.map +1 -0
- package/dist/main/effect/Ajax/Window/data/index.js +4 -6
- package/dist/main/effect/Ajax/Window/index.js +1 -4
- package/dist/main/effect/Ajax/index.js +2 -4
- package/dist/main/effect/Logging/index.js +2 -13
- package/dist/main/effect/Resource/data.js +20 -30
- package/dist/main/effect/Resource/data.js.map +1 -1
- package/dist/main/effect/Resource/index.js +3 -4
- package/dist/main/effect/Resource/schema.js +46 -45
- package/dist/main/effect/Resource/schema.js.map +1 -1
- package/dist/main/effect/Schemas/index.js +28 -0
- package/dist/main/effect/Schemas/index.js.map +1 -0
- package/dist/main/effect/index.js +5 -8
- package/dist/main/index.d.ts +359 -11
- package/dist/main/index.js +3 -3
- package/dist/main/resources/index.js +8 -7
- package/dist/main/resources/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/effect/Ajax/Window/data/types.js +0 -3
- package/dist/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/effect/Ajax/Window/index.js.map +0 -1
- package/dist/effect/index.js.map +0 -1
- package/dist/index.d.ts +0 -77
- package/dist/jsdelivr/effect/Ajax/Sections/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Sections/schema.js +0 -20
- package/dist/jsdelivr/effect/Ajax/Sections/schema.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/ShopifyRoutes.js +0 -38
- package/dist/jsdelivr/effect/Ajax/Window/data/ShopifyRoutes.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/StorefrontClientConfig.js +0 -16
- package/dist/jsdelivr/effect/Ajax/Window/data/StorefrontClientConfig.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/index.js +0 -6
- package/dist/jsdelivr/effect/Ajax/Window/data/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/types.js +0 -3
- package/dist/jsdelivr/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/Window/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/index.js.map +0 -1
- package/dist/jsdelivr/effect/Logging/index.js +0 -13
- package/dist/jsdelivr/effect/Logging/index.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/data.js +0 -17
- package/dist/jsdelivr/effect/Resource/data.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/index.js +0 -4
- package/dist/jsdelivr/effect/Resource/index.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/schema.js +0 -47
- package/dist/jsdelivr/effect/Resource/schema.js.map +0 -1
- package/dist/jsdelivr/effect/index.js +0 -8
- package/dist/jsdelivr/effect/index.js.map +0 -1
- package/dist/jsdelivr/index.js +0 -3
- package/dist/jsdelivr/index.js.map +0 -1
- package/dist/jsdelivr/resources/index.js +0 -9
- package/dist/jsdelivr/resources/index.js.map +0 -1
- package/dist/main/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/main/effect/Ajax/Window/data/index.js.map +0 -1
- package/dist/main/effect/Ajax/Window/data/types.js +0 -3
- package/dist/main/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/main/effect/Ajax/Window/index.js.map +0 -1
- package/dist/main/effect/Ajax/index.js.map +0 -1
- package/dist/main/effect/Logging/index.js.map +0 -1
- package/dist/main/effect/Resource/index.js.map +0 -1
- package/dist/main/effect/index.js.map +0 -1
- package/dist/main/index.js.map +0 -1
|
@@ -1,40 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
products_url: "/products",
|
|
13
|
-
cart_add_url: "/cart/add.js",
|
|
14
|
-
cart_change_url: "/cart/change.js",
|
|
15
|
-
cart_clear_url: "/cart/clear.js",
|
|
16
|
-
cart_update_url: "/cart/update.js",
|
|
17
|
-
cart_url: "/cart.js",
|
|
18
|
-
collections_url: "/collections",
|
|
19
|
-
predictive_search_url: "/search/suggest",
|
|
20
|
-
product_recommendations_url: "/recommendations/products",
|
|
21
|
-
root_url: "/",
|
|
22
|
-
search_url: "/search",
|
|
23
|
-
storefront_login_url: "/customer_authentication/login?return_to=%2Fservices%2Fliquid_rendering%2Fresource%3Ffast_storefront_renderer%3D1&locale=en"
|
|
24
|
-
};
|
|
25
|
-
class ShopifyRoutes extends Data.Class {
|
|
26
|
-
constructor() {
|
|
27
|
-
super({
|
|
28
|
-
...Defaults,
|
|
29
|
-
...window?.BrytDesigns?.routes || {}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const make = () => Data.case()({
|
|
34
|
-
...Defaults,
|
|
35
|
-
...window?.BrytDesigns?.routes || {}
|
|
1
|
+
import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
//#region src/effect/Ajax/Window/data/ShopifyRoutes.ts
|
|
6
|
+
var ShopifyRoutes_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
Defaults: () => Defaults,
|
|
8
|
+
Routes: () => Routes,
|
|
9
|
+
ShopifyRoutes: () => ShopifyRoutes,
|
|
10
|
+
layer: () => layer,
|
|
11
|
+
make: () => make
|
|
36
12
|
});
|
|
13
|
+
var Defaults = {
|
|
14
|
+
account_addresses_url: "/account/addresses",
|
|
15
|
+
account_login_url: "/account/login",
|
|
16
|
+
account_logout_url: "/account/logout",
|
|
17
|
+
account_recover_url: "/account/recover",
|
|
18
|
+
account_register_url: "/account/register",
|
|
19
|
+
account_url: "/account",
|
|
20
|
+
all_products_collection_url: "/collections/all",
|
|
21
|
+
product_url: "/products/:handle",
|
|
22
|
+
products_url: "/products",
|
|
23
|
+
cart_add_url: "/cart/add.js",
|
|
24
|
+
cart_change_url: "/cart/change.js",
|
|
25
|
+
cart_clear_url: "/cart/clear.js",
|
|
26
|
+
cart_update_url: "/cart/update.js",
|
|
27
|
+
cart_url: "/cart.js",
|
|
28
|
+
collections_url: "/collections",
|
|
29
|
+
predictive_search_url: "/search/suggest",
|
|
30
|
+
product_recommendations_url: "/recommendations/products",
|
|
31
|
+
root_url: "/",
|
|
32
|
+
search_url: "/search",
|
|
33
|
+
storefront_login_url: "/customer_authentication/login?return_to=%2Fservices%2Fliquid_rendering%2Fresource%3Ffast_storefront_renderer%3D1&locale=en"
|
|
34
|
+
};
|
|
35
|
+
var ShopifyRoutes = class extends Data.Class {
|
|
36
|
+
constructor() {
|
|
37
|
+
super({
|
|
38
|
+
...Defaults,
|
|
39
|
+
...window?.BrytDesigns?.routes || {}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var make = () => new ShopifyRoutes();
|
|
44
|
+
/**
|
|
45
|
+
* The route table, as a service.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately a `Context.Reference` rather than a `Context.Service`: a
|
|
48
|
+
* `Reference` carries its own default, so reading it leaves the effect's `R`
|
|
49
|
+
* channel at `never`. A `Service` would push `ShopifyRoutes` into `R` for
|
|
50
|
+
* every request effect in every downstream package, and those effects are run
|
|
51
|
+
* by plain Shopify themes through `Effect.runPromise` — which cannot provide
|
|
52
|
+
* anything. The default has to be the common path, and overriding it the
|
|
53
|
+
* exception.
|
|
54
|
+
*
|
|
55
|
+
* The default is evaluated lazily, on first read — but only once. Effect
|
|
56
|
+
* memoises a reference's default onto the reference itself
|
|
57
|
+
* (`Context.getDefaultValue`), so the table is read from `window` on the first
|
|
58
|
+
* Ajax call of the page and reused from then on.
|
|
59
|
+
*
|
|
60
|
+
* That is a deliberate change from the previous behaviour, where `make()` ran
|
|
61
|
+
* on every request and so picked up a later mutation of
|
|
62
|
+
* `window.BrytDesigns.routes`. Laziness buys the common case — a theme's inline
|
|
63
|
+
* script sets the routes before the first request, which module-scope
|
|
64
|
+
* evaluation would have missed — but a theme that rebinds routes *after* the
|
|
65
|
+
* first request must now provide them explicitly, with {@link layer} or
|
|
66
|
+
* `Effect.provideService`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // Override in a test, with no DOM in sight.
|
|
71
|
+
* Effect.provideService(effect, ShopifyRoutes.Routes, {
|
|
72
|
+
* ...ShopifyRoutes.Defaults,
|
|
73
|
+
* cart_url: "/fixtures/cart.js",
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
var Routes = Context.Reference("@brytdesigns/shopify-utils/ShopifyRoutes", { defaultValue: () => typeof window === "undefined" ? Defaults : make() });
|
|
78
|
+
/**
|
|
79
|
+
* Pins the route table to an explicit value.
|
|
80
|
+
*
|
|
81
|
+
* Only needed when something must override the window-derived default for a
|
|
82
|
+
* whole program rather than a single effect; `Effect.provideService` covers
|
|
83
|
+
* the single-effect case without building a layer.
|
|
84
|
+
*/
|
|
85
|
+
var layer = (routes) => Layer.succeed(Routes, routes);
|
|
86
|
+
//#endregion
|
|
87
|
+
export { Defaults, Routes, ShopifyRoutes, ShopifyRoutes_exports, layer, make };
|
|
37
88
|
|
|
38
|
-
export { Defaults, ShopifyRoutes, make };
|
|
39
|
-
//# sourceMappingURL=ShopifyRoutes.js.map
|
|
40
89
|
//# sourceMappingURL=ShopifyRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/effect/Ajax/Window/data/ShopifyRoutes.ts"],"
|
|
1
|
+
{"version":3,"file":"ShopifyRoutes.js","names":[],"sources":["../../../../../src/effect/Ajax/Window/data/ShopifyRoutes.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Data from \"effect/Data\";\nimport * as Layer from \"effect/Layer\";\nimport type { IShopifyRoutes } from \"./types.js\";\n\nexport const Defaults: IShopifyRoutes = {\n\taccount_addresses_url: \"/account/addresses\",\n\taccount_login_url: \"/account/login\",\n\taccount_logout_url: \"/account/logout\",\n\taccount_recover_url: \"/account/recover\",\n\taccount_register_url: \"/account/register\",\n\taccount_url: \"/account\",\n\tall_products_collection_url: \"/collections/all\",\n\tproduct_url: \"/products/:handle\",\n\tproducts_url: \"/products\",\n\tcart_add_url: \"/cart/add.js\",\n\tcart_change_url: \"/cart/change.js\",\n\tcart_clear_url: \"/cart/clear.js\",\n\tcart_update_url: \"/cart/update.js\",\n\tcart_url: \"/cart.js\",\n\tcollections_url: \"/collections\",\n\tpredictive_search_url: \"/search/suggest\",\n\tproduct_recommendations_url: \"/recommendations/products\",\n\troot_url: \"/\",\n\tsearch_url: \"/search\",\n\tstorefront_login_url:\n\t\t\"/customer_authentication/login?return_to=%2Fservices%2Fliquid_rendering%2Fresource%3Ffast_storefront_renderer%3D1&locale=en\",\n};\n\nexport class ShopifyRoutes extends Data.Class<IShopifyRoutes> {\n\tconstructor() {\n\t\tsuper({\n\t\t\t...Defaults,\n\t\t\t...(window?.BrytDesigns?.routes || {}),\n\t\t});\n\t}\n}\n\n// v4 removed Data.case. The class constructor already applies exactly these\n// defaults, so the factory collapses to it.\nexport const make = (): ShopifyRoutes => new ShopifyRoutes();\n\n/**\n * The route table, as a service.\n *\n * Deliberately a `Context.Reference` rather than a `Context.Service`: a\n * `Reference` carries its own default, so reading it leaves the effect's `R`\n * channel at `never`. A `Service` would push `ShopifyRoutes` into `R` for\n * every request effect in every downstream package, and those effects are run\n * by plain Shopify themes through `Effect.runPromise` — which cannot provide\n * anything. The default has to be the common path, and overriding it the\n * exception.\n *\n * The default is evaluated lazily, on first read — but only once. Effect\n * memoises a reference's default onto the reference itself\n * (`Context.getDefaultValue`), so the table is read from `window` on the first\n * Ajax call of the page and reused from then on.\n *\n * That is a deliberate change from the previous behaviour, where `make()` ran\n * on every request and so picked up a later mutation of\n * `window.BrytDesigns.routes`. Laziness buys the common case — a theme's inline\n * script sets the routes before the first request, which module-scope\n * evaluation would have missed — but a theme that rebinds routes *after* the\n * first request must now provide them explicitly, with {@link layer} or\n * `Effect.provideService`.\n *\n * @example\n * ```ts\n * // Override in a test, with no DOM in sight.\n * Effect.provideService(effect, ShopifyRoutes.Routes, {\n * ...ShopifyRoutes.Defaults,\n * cart_url: \"/fixtures/cart.js\",\n * });\n * ```\n */\nexport const Routes: Context.Reference<IShopifyRoutes> =\n\tContext.Reference<IShopifyRoutes>(\n\t\t\"@brytdesigns/shopify-utils/ShopifyRoutes\",\n\t\t{\n\t\t\t// Guarded rather than just `make()`: the class constructor reads `window`\n\t\t\t// unconditionally, and `window?.` does not protect against the identifier\n\t\t\t// being undeclared. Falling back to `Defaults` keeps the reference usable\n\t\t\t// from Node - which is what lets `ajax-client`'s tests run without jsdom.\n\t\t\tdefaultValue: () => (typeof window === \"undefined\" ? Defaults : make()),\n\t\t},\n\t);\n\n/**\n * Pins the route table to an explicit value.\n *\n * Only needed when something must override the window-derived default for a\n * whole program rather than a single effect; `Effect.provideService` covers\n * the single-effect case without building a layer.\n */\nexport const layer = (routes: IShopifyRoutes): Layer.Layer<never> =>\n\tLayer.succeed(Routes, routes);\n"],"mappings":";;;;;;;;;;;;AAKA,IAAa,WAA2B;CACvC,uBAAuB;CACvB,mBAAmB;CACnB,oBAAoB;CACpB,qBAAqB;CACrB,sBAAsB;CACtB,aAAa;CACb,6BAA6B;CAC7B,aAAa;CACb,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,iBAAiB;CACjB,UAAU;CACV,iBAAiB;CACjB,uBAAuB;CACvB,6BAA6B;CAC7B,UAAU;CACV,YAAY;CACZ,sBACC;AACF;AAEA,IAAa,gBAAb,cAAmC,KAAK,MAAsB;CAC7D,cAAc;EACb,MAAM;GACL,GAAG;GACH,GAAI,QAAQ,aAAa,UAAU,CAAC;EACrC,CAAC;CACF;AACD;AAIA,IAAa,aAA4B,IAAI,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmC3D,IAAa,SACZ,QAAQ,UACP,4CACA,EAKC,oBAAqB,OAAO,WAAW,cAAc,WAAW,KAAK,EACtE,CACD;;;;;;;;AASD,IAAa,SAAS,WACrB,MAAM,QAAQ,QAAQ,MAAM"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
const make = () => Data.case()({
|
|
11
|
-
...window.BrytDesigns.storefront.config
|
|
1
|
+
import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
//#region src/effect/Ajax/Window/data/StorefrontClientConfig.ts
|
|
4
|
+
var StorefrontClientConfig_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
StorefrontClientConfig: () => StorefrontClientConfig,
|
|
6
|
+
make: () => make
|
|
12
7
|
});
|
|
8
|
+
var StorefrontClientConfig = class extends Data.Class {
|
|
9
|
+
constructor() {
|
|
10
|
+
super({ ...window.BrytDesigns.storefront.config });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var make = () => new StorefrontClientConfig();
|
|
14
|
+
//#endregion
|
|
15
|
+
export { StorefrontClientConfig, StorefrontClientConfig_exports, make };
|
|
13
16
|
|
|
14
|
-
export { StorefrontClientConfig, make };
|
|
15
|
-
//# sourceMappingURL=StorefrontClientConfig.js.map
|
|
16
17
|
//# sourceMappingURL=StorefrontClientConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/effect/Ajax/Window/data/StorefrontClientConfig.ts"],"
|
|
1
|
+
{"version":3,"file":"StorefrontClientConfig.js","names":[],"sources":["../../../../../src/effect/Ajax/Window/data/StorefrontClientConfig.ts"],"sourcesContent":["import * as Data from \"effect/Data\";\nimport type { IStorefrontClientConfig } from \"./types.js\";\n\nexport class StorefrontClientConfig extends Data.Class<IStorefrontClientConfig> {\n\tconstructor() {\n\t\tsuper({\n\t\t\t...window.BrytDesigns.storefront.config,\n\t\t});\n\t}\n}\n\n// v4 removed Data.case. The class constructor already applies exactly these\n// defaults, so the factory collapses to it.\nexport const make = (): StorefrontClientConfig => new StorefrontClientConfig();\n"],"mappings":";;;;;;;AAGA,IAAa,yBAAb,cAA4C,KAAK,MAA+B;CAC/E,cAAc;EACb,MAAM,EACL,GAAG,OAAO,YAAY,WAAW,OAClC,CAAC;CACF;AACD;AAIA,IAAa,aAAqC,IAAI,uBAAuB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
//#region src/effect/Ajax/Window/data/StorefrontOrigin.ts
|
|
5
|
+
var StorefrontOrigin_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
Origin: () => Origin,
|
|
7
|
+
layer: () => layer
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* The origin every Ajax route is resolved against.
|
|
11
|
+
*
|
|
12
|
+
* Shopify's Ajax endpoints are same-origin paths (`/cart.js`), so this is
|
|
13
|
+
* `window.location.origin` on a storefront and the only reason the request
|
|
14
|
+
* layer needed a DOM at all. Lifting it to a `Context.Reference` means
|
|
15
|
+
* `ajax-client` can build a request without one, which is what makes its
|
|
16
|
+
* tests runnable outside jsdom.
|
|
17
|
+
*
|
|
18
|
+
* A `Reference` rather than a `Service` for the same reason as
|
|
19
|
+
* {@link ShopifyRoutes.Routes}: the default must work with no provision, so
|
|
20
|
+
* themes can keep calling `Effect.runPromise` directly.
|
|
21
|
+
*
|
|
22
|
+
* Read lazily. `window.location.origin` is stable within a page, but reading
|
|
23
|
+
* it at module scope would still break any environment that imports this
|
|
24
|
+
* module before a DOM exists.
|
|
25
|
+
*/
|
|
26
|
+
var Origin = Context.Reference("@brytdesigns/shopify-utils/StorefrontOrigin", { defaultValue: () => typeof window === "undefined" ? "" : window.location.origin });
|
|
27
|
+
/** Pins the origin for a whole program. */
|
|
28
|
+
var layer = (origin) => Layer.succeed(Origin, origin);
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Origin, StorefrontOrigin_exports, layer };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=StorefrontOrigin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorefrontOrigin.js","names":[],"sources":["../../../../../src/effect/Ajax/Window/data/StorefrontOrigin.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\n\n/**\n * The origin every Ajax route is resolved against.\n *\n * Shopify's Ajax endpoints are same-origin paths (`/cart.js`), so this is\n * `window.location.origin` on a storefront and the only reason the request\n * layer needed a DOM at all. Lifting it to a `Context.Reference` means\n * `ajax-client` can build a request without one, which is what makes its\n * tests runnable outside jsdom.\n *\n * A `Reference` rather than a `Service` for the same reason as\n * {@link ShopifyRoutes.Routes}: the default must work with no provision, so\n * themes can keep calling `Effect.runPromise` directly.\n *\n * Read lazily. `window.location.origin` is stable within a page, but reading\n * it at module scope would still break any environment that imports this\n * module before a DOM exists.\n */\nexport const Origin: Context.Reference<string> = Context.Reference<string>(\n\t\"@brytdesigns/shopify-utils/StorefrontOrigin\",\n\t{\n\t\tdefaultValue: () =>\n\t\t\ttypeof window === \"undefined\" ? \"\" : window.location.origin,\n\t},\n);\n\n/** Pins the origin for a whole program. */\nexport const layer = (origin: string): Layer.Layer<never> =>\n\tLayer.succeed(Origin, origin);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,SAAoC,QAAQ,UACxD,+CACA,EACC,oBACC,OAAO,WAAW,cAAc,KAAK,OAAO,SAAS,OACvD,CACD;;AAGA,IAAa,SAAS,WACrB,MAAM,QAAQ,QAAQ,MAAM"}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { AllowedRouteOrigins_exports } from "./AllowedRouteOrigins.js";
|
|
3
|
+
import { ShopifyRoutes_exports } from "./ShopifyRoutes.js";
|
|
4
|
+
import { StorefrontClientConfig_exports } from "./StorefrontClientConfig.js";
|
|
5
|
+
import { StorefrontOrigin_exports } from "./StorefrontOrigin.js";
|
|
6
|
+
//#region src/effect/Ajax/Window/data/index.ts
|
|
7
|
+
var data_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
AllowedRouteOrigins: () => AllowedRouteOrigins_exports,
|
|
9
|
+
ShopifyRoutes: () => ShopifyRoutes_exports,
|
|
10
|
+
StorefrontClientConfig: () => StorefrontClientConfig_exports,
|
|
11
|
+
StorefrontOrigin: () => StorefrontOrigin_exports
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AllowedRouteOrigins_exports as AllowedRouteOrigins, ShopifyRoutes_exports as ShopifyRoutes, StorefrontClientConfig_exports as StorefrontClientConfig, StorefrontOrigin_exports as StorefrontOrigin, data_exports };
|
|
15
|
+
|
|
6
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../src/effect/Ajax/Window/data/index.ts"],"sourcesContent":["export * as AllowedRouteOrigins from \"./AllowedRouteOrigins.js\";\nexport * as ShopifyRoutes from \"./ShopifyRoutes.js\";\nexport * as StorefrontClientConfig from \"./StorefrontClientConfig.js\";\nexport * as StorefrontOrigin from \"./StorefrontOrigin.js\";\n"],"mappings":""}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { schema_exports } from "./Sections/schema.js";
|
|
3
|
+
import "./Sections/index.js";
|
|
4
|
+
import { data_exports } from "./Window/data/index.js";
|
|
5
|
+
import "./Window/index.js";
|
|
6
|
+
//#region src/effect/Ajax/index.ts
|
|
7
|
+
var Ajax_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
Sections: () => schema_exports,
|
|
9
|
+
Window: () => data_exports
|
|
10
|
+
});
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Ajax_exports, schema_exports as Sections, data_exports as Window };
|
|
13
|
+
|
|
4
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/effect/Ajax/index.ts"],"sourcesContent":["export * from \"./Sections/index.js\";\nexport * from \"./Window/index.js\";\n"],"mappings":""}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as References from "effect/References";
|
|
4
|
+
//#region src/effect/Logging/index.ts
|
|
5
|
+
var Logging_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
filterLevelOrNever: () => filterLevelOrNever,
|
|
7
|
+
makeNamespacedLogSpan: () => makeNamespacedLogSpan
|
|
8
|
+
});
|
|
9
|
+
var filterLevelOrNever = (level, effect) => Effect.gen(function* () {
|
|
10
|
+
if ((yield* References.MinimumLogLevel) !== level) return yield* effect;
|
|
8
11
|
});
|
|
9
|
-
|
|
12
|
+
var makeNamespacedLogSpan = (prefix) => (label) => Effect.withLogSpan(`${prefix}:${label}`);
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Logging_exports, filterLevelOrNever, makeNamespacedLogSpan };
|
|
10
15
|
|
|
11
|
-
export { filterLevelOrNever, makeNamespacedLogSpan };
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
13
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/effect/Logging/index.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport type * as LogLevel from \"effect/LogLevel\";\nimport * as References from \"effect/References\";\n\nexport const filterLevelOrNever = <A, E, R>(\n\tlevel: LogLevel.LogLevel,\n\teffect: Effect.Effect<A, E, R>,\n) =>\n\tEffect.gen(function* () {\n\t\t// v4: the minimum log level is a Context.Reference rather than a FiberRef,\n\t\t// and levels are string literals rather than branded objects.\n\t\tconst logLevel = yield* References.MinimumLogLevel;\n\t\tif (logLevel !== level) return yield* effect;\n\t});\n\nexport const makeNamespacedLogSpan = (prefix: string) => (label: string) =>\n\tEffect.withLogSpan(`${prefix}:${label}`);\n"],"mappings":";;;;;;;;AAIA,IAAa,sBACZ,OACA,WAEA,OAAO,IAAI,aAAa;CAIvB,KAAI,OADoB,WAAW,qBAClB,OAAO,OAAO,OAAO;AACvC,CAAC;AAEF,IAAa,yBAAyB,YAAoB,UACzD,OAAO,YAAY,GAAG,OAAO,GAAG,OAAO"}
|
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) => Effect.gen(function* () {
|
|
10
|
-
const [actualId, actualType] = yield* Effect.all(
|
|
11
|
-
[Schema.decode(ID)(id), Schema.decode(Type)(type)],
|
|
12
|
-
{
|
|
13
|
-
concurrency: "unbounded"
|
|
14
|
-
}
|
|
15
|
-
);
|
|
16
|
-
return `gid://shopify/${actualType}/${actualId}`;
|
|
1
|
+
import { GID, ID, Type } from "./schema.js";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as SchemaGetter from "effect/SchemaGetter";
|
|
5
|
+
//#region src/effect/Resource/data.ts
|
|
6
|
+
var format = ({ id, type }) => Effect.gen(function* () {
|
|
7
|
+
const [actualId, actualType] = yield* Effect.all([Schema.decodeEffect(ID)(id), Schema.decodeEffect(Type)(type)], { concurrency: "unbounded" });
|
|
8
|
+
return `gid://shopify/${actualType}/${actualId}`;
|
|
17
9
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)(input);
|
|
30
|
-
|
|
10
|
+
/**
|
|
11
|
+
* v4 replaces `Schema.transformOrFail` with `decodeTo` plus `SchemaGetter`
|
|
12
|
+
* transformations. The decode direction never fails, so it is a plain
|
|
13
|
+
* `transform`; the encode direction is refused outright, which `forbidden`
|
|
14
|
+
* expresses directly rather than by constructing an issue by hand.
|
|
15
|
+
*/
|
|
16
|
+
var parse = (input) => Schema.decodeEffect(GID.pipe(Schema.decodeTo(ID, {
|
|
17
|
+
decode: SchemaGetter.transform((value) => `${value}`.split("/").pop()),
|
|
18
|
+
encode: SchemaGetter.forbidden(() => "Encoding an ID to a GID is not allowed. Use the format function to convert IDs to GIDs.")
|
|
19
|
+
})))(input);
|
|
20
|
+
//#endregion
|
|
31
21
|
export { format, parse };
|
|
32
|
-
|
|
22
|
+
|
|
33
23
|
//# sourceMappingURL=data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../../src/effect/Resource/data.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport { GID, ID, Type } from \"./schema.js\";\n\ntype FormatOptions<T extends ID, R extends Type> = {\n\tid: T;\n\ttype: R;\n};\n\nexport const format = <const T extends ID, const R extends Type>({\n\tid,\n\ttype,\n}: FormatOptions<T, R>) =>\n\tEffect.gen(function* () {\n\t\tconst [actualId, actualType] = yield* Effect.all(\n\t\t\t[Schema.decodeEffect(ID)(id), Schema.decodeEffect(Type)(type)],\n\t\t\t{\n\t\t\t\tconcurrency: \"unbounded\",\n\t\t\t},\n\t\t);\n\t\treturn `gid://shopify/${actualType}/${actualId}` as `gid://shopify/${R}/${T}`;\n\t});\n\n/**\n * v4 replaces `Schema.transformOrFail` with `decodeTo` plus `SchemaGetter`\n * transformations. The decode direction never fails, so it is a plain\n * `transform`; the encode direction is refused outright, which `forbidden`\n * expresses directly rather than by constructing an issue by hand.\n */\nexport const parse = (input: string) =>\n\tSchema.decodeEffect(\n\t\tGID.pipe(\n\t\t\tSchema.decodeTo(ID, {\n\t\t\t\tdecode: SchemaGetter.transform(\n\t\t\t\t\t(value: string) => `${value}`.split(\"/\").pop() as ID,\n\t\t\t\t),\n\t\t\t\tencode: SchemaGetter.forbidden(\n\t\t\t\t\t() =>\n\t\t\t\t\t\t\"Encoding an ID to a GID is not allowed. Use the format function to convert IDs to GIDs.\",\n\t\t\t\t),\n\t\t\t}),\n\t\t),\n\t)(input);\n"],"mappings":";;;;;AAUA,IAAa,UAAoD,EAChE,IACA,WAEA,OAAO,IAAI,aAAa;CACvB,MAAM,CAAC,UAAU,cAAc,OAAO,OAAO,IAC5C,CAAC,OAAO,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC,GAC7D,EACC,aAAa,YACd,CACD;CACA,OAAO,iBAAiB,WAAW,GAAG;AACvC,CAAC;;;;;;;AAQF,IAAa,SAAS,UACrB,OAAO,aACN,IAAI,KACH,OAAO,SAAS,IAAI;CACnB,QAAQ,aAAa,WACnB,UAAkB,GAAG,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,CAC9C;CACA,QAAQ,aAAa,gBAEnB,yFACF;AACD,CAAC,CACF,CACD,CAAC,CAAC,KAAK"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { GID, ID, Type } from "./schema.js";
|
|
3
|
+
import { format, parse } from "./data.js";
|
|
4
|
+
//#region src/effect/Resource/index.ts
|
|
5
|
+
var Resource_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
GID: () => GID,
|
|
7
|
+
ID: () => ID,
|
|
8
|
+
Type: () => Type,
|
|
9
|
+
format: () => format,
|
|
10
|
+
parse: () => parse
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { GID, ID, Resource_exports, Type, format, parse };
|
|
14
|
+
|
|
4
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/effect/Resource/index.ts"],"sourcesContent":["export * from \"./data.js\";\nexport { GID, ID, Type } from \"./schema.js\";\n"],"mappings":""}
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
import { FiniteFromNumericString } from "../Schemas/index.js";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
//#region src/effect/Resource/schema.ts
|
|
4
|
+
var Type = Schema.Literals([
|
|
5
|
+
"Cart",
|
|
6
|
+
"Collection",
|
|
7
|
+
"Customer",
|
|
8
|
+
"DeliveryCarrierService",
|
|
9
|
+
"DeliveryLocationGroup",
|
|
10
|
+
"DeliveryProfile",
|
|
11
|
+
"DeliveryZone",
|
|
12
|
+
"DraftOrder",
|
|
13
|
+
"DraftOrderLineItem",
|
|
14
|
+
"Duty",
|
|
15
|
+
"EmailTemplate",
|
|
16
|
+
"Fulfillment",
|
|
17
|
+
"FulfullmentEvent",
|
|
18
|
+
"FullfullmentService",
|
|
19
|
+
"InventoryItem",
|
|
20
|
+
"InventoryLevel",
|
|
21
|
+
"LineItem",
|
|
22
|
+
"Location",
|
|
23
|
+
"MarketingEvent",
|
|
24
|
+
"MediaImage",
|
|
25
|
+
"Metafield",
|
|
26
|
+
"OnlineStoreArticle",
|
|
27
|
+
"OnlineStoreBlog",
|
|
28
|
+
"OnlineStorePage",
|
|
29
|
+
"Order",
|
|
30
|
+
"OrderTransaction",
|
|
31
|
+
"Product",
|
|
32
|
+
"ProductImage",
|
|
33
|
+
"ProductVariant",
|
|
34
|
+
"Refund",
|
|
35
|
+
"Shop",
|
|
36
|
+
"StaffMember",
|
|
37
|
+
"Theme"
|
|
38
|
+
]);
|
|
39
|
+
var GID = Schema.String.check(Schema.isStartingWith("gid://shopify/"));
|
|
40
|
+
var ID = Schema.Union([
|
|
41
|
+
Schema.Number,
|
|
42
|
+
FiniteFromNumericString,
|
|
43
|
+
Schema.String
|
|
44
|
+
]);
|
|
45
|
+
//#endregion
|
|
45
46
|
export { GID, ID, Type };
|
|
46
|
-
|
|
47
|
+
|
|
47
48
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/effect/Resource/schema.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as Schemas from \"../Schemas/index.js\";\n\nexport type Type = Schema.Schema.Type<typeof Type>;\nexport const Type = Schema.Literals([\n\t\"Cart\",\n\t\"Collection\",\n\t\"Customer\",\n\t\"DeliveryCarrierService\",\n\t\"DeliveryLocationGroup\",\n\t\"DeliveryProfile\",\n\t\"DeliveryZone\",\n\t\"DraftOrder\",\n\t\"DraftOrderLineItem\",\n\t\"Duty\",\n\t\"EmailTemplate\",\n\t\"Fulfillment\",\n\t\"FulfullmentEvent\",\n\t\"FullfullmentService\",\n\t\"InventoryItem\",\n\t\"InventoryLevel\",\n\t\"LineItem\",\n\t\"Location\",\n\t\"MarketingEvent\",\n\t\"MediaImage\",\n\t\"Metafield\",\n\t\"OnlineStoreArticle\",\n\t\"OnlineStoreBlog\",\n\t\"OnlineStorePage\",\n\t\"Order\",\n\t\"OrderTransaction\",\n\t\"Product\",\n\t\"ProductImage\",\n\t\"ProductVariant\",\n\t\"Refund\",\n\t\"Shop\",\n\t\"StaffMember\",\n\t\"Theme\",\n]);\n\nexport type GID = Schema.Codec.Encoded<typeof GID>;\nexport const GID = Schema.String.check(Schema.isStartingWith(\"gid://shopify/\"));\n\n/**\n * A Shopify id: a number, a numeric string decoded to one, or any other\n * string left as it is - a line item key, a handle, an empty string.\n *\n * The middle member was `Schema.NumberFromString`, which in Effect 4 never\n * fails, so `String` was unreachable and every non-numeric id decoded to NaN.\n * See `Schemas.FiniteFromNumericString`.\n */\nexport type ID = Schema.Codec.Encoded<typeof ID>;\nexport const ID = Schema.Union([\n\tSchema.Number,\n\tSchemas.FiniteFromNumericString,\n\tSchema.String,\n]);\n"],"mappings":";;;AAIA,IAAa,OAAO,OAAO,SAAS;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AAGD,IAAa,MAAM,OAAO,OAAO,MAAM,OAAO,eAAe,gBAAgB,CAAC;AAW9E,IAAa,KAAK,OAAO,MAAM;CAC9B,OAAO;CACP;CACA,OAAO;AACR,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as SchemaIssue from "effect/SchemaIssue";
|
|
5
|
+
import * as Arr from "effect/Array";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import * as SchemaParser from "effect/SchemaParser";
|
|
8
|
+
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
9
|
+
//#region src/effect/Schemas/index.ts
|
|
10
|
+
var Schemas_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
ArrayDroppingInvalid: () => ArrayDroppingInvalid,
|
|
12
|
+
FiniteFromNumericString: () => FiniteFromNumericString
|
|
13
|
+
});
|
|
14
|
+
var formatIssue = SchemaIssue.makeFormatterDefault();
|
|
15
|
+
/**
|
|
16
|
+
* An array that decodes element by element and drops the elements that fail.
|
|
17
|
+
*
|
|
18
|
+
* `Schema.Array` fails the whole array on its first bad element, which is right
|
|
19
|
+
* for a request body and wrong for a list of search results: one product with a
|
|
20
|
+
* malformed price would reject every product, collection and page around it.
|
|
21
|
+
* This keeps the rest.
|
|
22
|
+
*
|
|
23
|
+
* Built with `declareConstructor` rather than `Schema.Array(item.pipe(
|
|
24
|
+
* Schema.catchDecoding(...)))`. Recovering to `Option.none()` inside an array
|
|
25
|
+
* does not drop the element: v4's array parser reports a missing element as a
|
|
26
|
+
* `MissingKey` issue, so the array fails anyway. A declaration owns the whole
|
|
27
|
+
* array and can leave elements out.
|
|
28
|
+
*
|
|
29
|
+
* The type is `ReadonlyArray<Type>`, identical to `Schema.Array`'s, so a
|
|
30
|
+
* schema can switch to this without changing what it decodes to. Input that is
|
|
31
|
+
* not an array at all still fails: that is a broken response, not a bad item.
|
|
32
|
+
*
|
|
33
|
+
* Each dropped element is logged at `Debug` with its index and the issue, so
|
|
34
|
+
* it is visible wherever the caller has turned debug logging on and silent
|
|
35
|
+
* everywhere else.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Schemas } from "@brytdesigns/shopify-utils/effect";
|
|
40
|
+
*
|
|
41
|
+
* const Results = Schema.Struct({
|
|
42
|
+
* products: Schemas.ArrayDroppingInvalid(Product),
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
var ArrayDroppingInvalid = (item) => Schema.declareConstructor()([item], ([codec]) => {
|
|
47
|
+
const decode = SchemaParser.decodeUnknownEffect(codec);
|
|
48
|
+
return (input, ast, options) => {
|
|
49
|
+
if (!Array.isArray(input)) return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
50
|
+
return Effect.forEach(input, (element, index) => decode(element, options).pipe(Effect.map(Option.some), Effect.catch((issue) => Effect.logDebug("Dropped an array element that failed to decode", {
|
|
51
|
+
index,
|
|
52
|
+
issue: formatIssue(issue)
|
|
53
|
+
}).pipe(Effect.as(Option.none()))))).pipe(Effect.map(Arr.getSomes));
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* A string holding a number, decoded to that number. Anything else fails.
|
|
58
|
+
*
|
|
59
|
+
* What Effect 3's `Schema.NumberFromString` was, and Effect 4's is not. v4's
|
|
60
|
+
* is plain `Number(s)` and never fails: "abc" decodes to NaN, and "" and
|
|
61
|
+
* whitespace to 0. `Schema.FiniteFromString` rejects NaN and Infinity but
|
|
62
|
+
* still reads a blank string as 0. Neither is safe in a union whose later
|
|
63
|
+
* members are meant to catch what the numeric one refuses, and neither should
|
|
64
|
+
* turn a missing price into a free product.
|
|
65
|
+
*
|
|
66
|
+
* Accepts what v3 accepted, minus the non-finite values: a string with at
|
|
67
|
+
* least one non-whitespace character that `Number()` reads as finite. So
|
|
68
|
+
* `"10.00"` is 10, `" 42 "` is 42, and `""`, `" "`, `"abc"` and `"NaN"`
|
|
69
|
+
* fail.
|
|
70
|
+
*/
|
|
71
|
+
var FiniteFromNumericString = Schema.String.check(Schema.isPattern(/\S/, { expected: "a non-blank string" })).pipe(Schema.decodeTo(Schema.Finite, SchemaTransformation.numberFromString));
|
|
72
|
+
//#endregion
|
|
73
|
+
export { ArrayDroppingInvalid, FiniteFromNumericString, Schemas_exports };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/effect/Schemas/index.ts"],"sourcesContent":["import * as Arr from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaIssue from \"effect/SchemaIssue\";\nimport * as SchemaParser from \"effect/SchemaParser\";\nimport * as SchemaTransformation from \"effect/SchemaTransformation\";\n\nconst formatIssue = SchemaIssue.makeFormatterDefault();\n\n/**\n * An array that decodes element by element and drops the elements that fail.\n *\n * `Schema.Array` fails the whole array on its first bad element, which is right\n * for a request body and wrong for a list of search results: one product with a\n * malformed price would reject every product, collection and page around it.\n * This keeps the rest.\n *\n * Built with `declareConstructor` rather than `Schema.Array(item.pipe(\n * Schema.catchDecoding(...)))`. Recovering to `Option.none()` inside an array\n * does not drop the element: v4's array parser reports a missing element as a\n * `MissingKey` issue, so the array fails anyway. A declaration owns the whole\n * array and can leave elements out.\n *\n * The type is `ReadonlyArray<Type>`, identical to `Schema.Array`'s, so a\n * schema can switch to this without changing what it decodes to. Input that is\n * not an array at all still fails: that is a broken response, not a bad item.\n *\n * Each dropped element is logged at `Debug` with its index and the issue, so\n * it is visible wherever the caller has turned debug logging on and silent\n * everywhere else.\n *\n * @example\n * ```ts\n * import { Schemas } from \"@brytdesigns/shopify-utils/effect\";\n *\n * const Results = Schema.Struct({\n * products: Schemas.ArrayDroppingInvalid(Product),\n * });\n * ```\n */\nexport const ArrayDroppingInvalid = <S extends Schema.Constraint>(item: S) =>\n\tSchema.declareConstructor<\n\t\tReadonlyArray<S[\"Type\"]>,\n\t\tReadonlyArray<S[\"Encoded\"]>\n\t>()([item], ([codec]) => {\n\t\tconst decode = SchemaParser.decodeUnknownEffect(codec);\n\n\t\treturn (input, ast, options) => {\n\t\t\tif (!Array.isArray(input)) {\n\t\t\t\treturn Effect.fail(new SchemaIssue.InvalidType(ast, input, options));\n\t\t\t}\n\n\t\t\treturn Effect.forEach(input, (element, index) =>\n\t\t\t\tdecode(element, options).pipe(\n\t\t\t\t\tEffect.map(Option.some),\n\t\t\t\t\tEffect.catch((issue) =>\n\t\t\t\t\t\tEffect.logDebug(\"Dropped an array element that failed to decode\", {\n\t\t\t\t\t\t\tindex,\n\t\t\t\t\t\t\tissue: formatIssue(issue),\n\t\t\t\t\t\t}).pipe(Effect.as(Option.none())),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t).pipe(Effect.map(Arr.getSomes));\n\t\t};\n\t});\n\n/**\n * A string holding a number, decoded to that number. Anything else fails.\n *\n * What Effect 3's `Schema.NumberFromString` was, and Effect 4's is not. v4's\n * is plain `Number(s)` and never fails: \"abc\" decodes to NaN, and \"\" and\n * whitespace to 0. `Schema.FiniteFromString` rejects NaN and Infinity but\n * still reads a blank string as 0. Neither is safe in a union whose later\n * members are meant to catch what the numeric one refuses, and neither should\n * turn a missing price into a free product.\n *\n * Accepts what v3 accepted, minus the non-finite values: a string with at\n * least one non-whitespace character that `Number()` reads as finite. So\n * `\"10.00\"` is 10, `\" 42 \"` is 42, and `\"\"`, `\" \"`, `\"abc\"` and `\"NaN\"`\n * fail.\n */\nexport const FiniteFromNumericString = Schema.String.check(\n\tSchema.isPattern(/\\S/, { expected: \"a non-blank string\" }),\n).pipe(Schema.decodeTo(Schema.Finite, SchemaTransformation.numberFromString));\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAM,cAAc,YAAY,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCrD,IAAa,wBAAqD,SACjE,OAAO,mBAGL,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW;CACxB,MAAM,SAAS,aAAa,oBAAoB,KAAK;CAErD,QAAQ,OAAO,KAAK,YAAY;EAC/B,IAAI,CAAC,MAAM,QAAQ,KAAK,GACvB,OAAO,OAAO,KAAK,IAAI,YAAY,YAAY,KAAK,OAAO,OAAO,CAAC;EAGpE,OAAO,OAAO,QAAQ,QAAQ,SAAS,UACtC,OAAO,SAAS,OAAO,CAAC,CAAC,KACxB,OAAO,IAAI,OAAO,IAAI,GACtB,OAAO,OAAO,UACb,OAAO,SAAS,kDAAkD;GACjE;GACA,OAAO,YAAY,KAAK;EACzB,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,OAAO,KAAK,CAAC,CAAC,CACjC,CACD,CACD,CAAC,CAAC,KAAK,OAAO,IAAI,IAAI,QAAQ,CAAC;CAChC;AACD,CAAC;;;;;;;;;;;;;;;;AAiBF,IAAa,0BAA0B,OAAO,OAAO,MACpD,OAAO,UAAU,MAAM,EAAE,UAAU,qBAAqB,CAAC,CAC1D,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,QAAQ,qBAAqB,gBAAgB,CAAC"}
|