Skip to content

Commit

Permalink
Project update. [p][robotic]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswrks committed Mar 22, 2024
1 parent a2831cb commit c0a08d1
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

[production]
node >= 20.9.0
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Locals

Expand Down
8 changes: 4 additions & 4 deletions .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ DOTENV_VAULT_MAIN="7GW98NfL4hM4N6HbfeDXCKreVxKvcVPupFRnZ8XJ+pomaQ=="
DOTENV_VAULT_MAIN_VERSION=1

# dev
DOTENV_VAULT_DEV="a+hP6nwf4CqONa9HrqVRAS9dngtgA6QHT3l5D2DEHArCV934o/YKSUa7mJ4cah+U/cRf4bGUGgblBQqQW9vIWtMgDOOQA9E8Mf6NBX79DKJZOwODwrIYBfRHH6KcrD+NNOhOmSeJ5q+tado5J5Dyq3sBkWiQ7PkAgvEeMUnociUlfQSu+tXqXUJwm0zaY2PmCwanWeZMLFddlZTETwa+BvkPaOPM29XfeyJD/tUs9LRuqs7OKD7Qy+hM7ku2Nd3AIA=="
DOTENV_VAULT_DEV_VERSION=467
DOTENV_VAULT_DEV="kSpcS87N4T+DP0j67/NEgV2VkFKSfZ0wtuR/JNYOGbnmYwCwIuqLefBaluLkYzZcwDMzh/GdbnM0fhxm8IpxeNI/wCR00nnCApNOt9nJN6aXA/XF8ebczvOvVW0k1FdH7qAVd/6+DtjO5+RH2/hX3cXhy9f9bZ4t1PT4J/c970H5xgaulwjwPOUY4X/APedGp0hRuLfqsDpkULk6yHwngyGvmJBQEwrOh6dEZqLJP4xleavS7ErfXSbF5oh861jy1Q=="
DOTENV_VAULT_DEV_VERSION=469

# ci
DOTENV_VAULT_CI="Qf4313mFcLvwmOisZB1rijt+IuiWsVk9z8k74kBCRWWLdfqRvNKZBSOWjzK9OuCwByPvgINYL4+8qr752as6FFMGFtXpLlOewG36R7JJv+caYksGYy/x0YJIEFGyIPHf1hlat/C2MVp1l+HF/T0bG9laB0yDKcKc84E10HNVHw=="
DOTENV_VAULT_CI_VERSION=467
DOTENV_VAULT_CI="tSs3/1qDGDC5N/LUwefxIQMn/m/K+HOVxRhGsIegmRtVYLKU+TjrjyRhwyDoKjlNqZaOoihxsLbFqPL2Pj4ZaiuokBIbHzv7sgg6kqKm21nlAnYZ/cKfhAIf8iIe7Qud6fP0gHJ+3d9a83LgRlh0dvMO4D8CJGLspEbNjHgpIg=="
DOTENV_VAULT_CI_VERSION=469

# stage
DOTENV_VAULT_STAGE="aRP8su2YV4jZu3w1HZ/SLaots0IwJDFw75TCpvXEFeNp7tw="
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Default

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Locals

Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Packages

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @note This entire file will be updated automatically.
* @note Instead of editing here, please review `./settings.mjs`.
*
* Last generated using `./settings.mjs` Mar 22, 2024 7:11 AM UTC.
* Last generated using `./settings.mjs` Mar 22, 2024 7:58 AM UTC.
*/
{
"editor.formatOnType": false,
Expand Down
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Generated data.
# <generated:start>

# Last generated Mar 22, 2024 7:11 AM UTC.
# Last generated Mar 22, 2024 7:58 AM UTC.

# Locals

Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.0.920",
"version": "1.0.921",
"license": "GPL-3.0-or-later",
"name": "@clevercanyon/utilities",
"description": "Utilities for JavaScript apps running in any environment.",
Expand Down
58 changes: 58 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { $brand, $env, $obj, $str, $time, $url, $user, type $type } from '#index
* Defines types.
*/
export type BaseURLOptions = { parsed?: boolean };
export type RootR2OriginURLOptions = { parsed?: boolean };
export type RootR2BaseURLOptions = { parsed?: boolean };
export type R2OriginURLOptions = { parsed?: boolean };
export type R2BaseURLOptions = { parsed?: boolean };

Expand Down Expand Up @@ -115,6 +117,62 @@ export const baseURL = $fnꓺmemo(
},
);

/**
* Checks if environment has an app’s root R2 origin URL.
*
* @returns True if environment has an app’s root R2 origin URL.
*/
export const hasRootR2OriginURL = $fnꓺmemo((): boolean => {
return $env.get('APP_ROOT_R2_ORIGIN_URL') ? true : false;
});

/**
* Gets current app’s root R2 origin URL.
*
* @param options Options (all optional); {@see RootR2OriginURLOptions}.
*
* @returns Current app’s root R2 origin URL.
*
* @note Unable to deep freeze a URL, but we would do so if possible.
* For now, we just declare it readonly using a TypeScript return type.
*/
export const rootR2OriginURL = $fnꓺmemo(
{ deep: true, maxSize: 2 },
<Options extends RootR2OriginURLOptions>(options?: Options): Options extends RootR2OriginURLOptions & { parsed: true } ? $type.ReadonlyDeep<$type.URL> : string => {
const opts = $obj.defaults({}, options || {}, { parsed: false }) as Required<RootR2OriginURLOptions>,
value = $str.rTrim($env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'string', require: true }), '/');
return (opts.parsed ? $url.parse(value) : value) as ReturnType<typeof rootR2OriginURL<Options>>;
},
);

/**
* Checks if environment has an app’s root R2 base URL.
*
* @returns True if environment has an app’s root R2 base URL.
*/
export const hasRootR2BaseURL = $fnꓺmemo((): boolean => {
return $env.get('APP_ROOT_R2_BASE_URL') || hasRootR2OriginURL() ? true : false;
});

/**
* Gets current app’s root R2 base URL.
*
* @param options Options (all optional); {@see RootR2BaseURLOptions}.
*
* @returns Current app’s root R2 base URL.
*
* @note Unable to deep freeze a URL, but we would do so if possible.
* For now, we just declare it readonly using a TypeScript return type.
*/
export const rootR2BaseURL = $fnꓺmemo(
{ deep: true, maxSize: 2 },
<Options extends RootR2BaseURLOptions>(options?: Options): Options extends RootR2BaseURLOptions & { parsed: true } ? $type.ReadonlyDeep<$type.URL> : string => {
const opts = $obj.defaults({}, options || {}, { parsed: false }) as Required<RootR2BaseURLOptions>,
value = $env.get('APP_ROOT_R2_BASE_URL', { type: 'string', default: '' }) || rootR2OriginURL() + '/app/' + pkgSlug() + '/';
return (opts.parsed ? $url.parse(value) : value) as ReturnType<typeof rootR2BaseURL<Options>>;
},
);

/**
* Checks if environment has an app’s R2 origin URL.
*
Expand Down
12 changes: 12 additions & 0 deletions src/tests/brand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest';

const __origAppPkgName__ = $env.get('APP_PKG_NAME', { type: 'unknown' });
const __origAppBaseURL__ = $env.get('APP_BASE_URL', { type: 'unknown' });
const __origAppRootR2OriginURL__ = $env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppRootR2BaseURL__ = $env.get('APP_ROOT_R2_BASE_URL', { type: 'unknown' });
const __origAppR2OriginURL__ = $env.get('APP_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppR2BaseURL__ = $env.get('APP_R2_BASE_URL', { type: 'unknown' });
const __origAppBrandProps__ = $env.get('APP_BRAND_PROPS', { type: 'unknown' });
Expand All @@ -16,6 +18,8 @@ describe('$brand', async () => {
beforeAll(async () => {
$env.set('APP_PKG_NAME', '@clevercanyon/x.tld');
$env.set('APP_BASE_URL', 'https://x.tld/base/');
$env.set('APP_ROOT_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_ROOT_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_BRAND_PROPS', { type: 'site' });
Expand All @@ -24,6 +28,8 @@ describe('$brand', async () => {
afterAll(async () => {
$env.set('APP_PKG_NAME', __origAppPkgName__);
$env.set('APP_BASE_URL', __origAppBaseURL__);
$env.set('APP_ROOT_R2_ORIGIN_URL', __origAppRootR2OriginURL__);
$env.set('APP_ROOT_R2_BASE_URL', __origAppRootR2BaseURL__);
$env.set('APP_R2_ORIGIN_URL', __origAppR2OriginURL__);
$env.set('APP_R2_BASE_URL', __origAppR2BaseURL__);
$env.set('APP_BRAND_PROPS', __origAppBrandProps__);
Expand All @@ -37,6 +43,12 @@ describe('$brand', async () => {
$app.hasBaseURL.flush(),
$app.baseURL.flush(),
//
$app.hasRootR2OriginURL.flush(),
$app.rootR2OriginURL.flush(),
//
$app.hasRootR2BaseURL.flush(),
$app.rootR2BaseURL.flush(),
//
$app.hasR2OriginURL.flush(),
$app.r2OriginURL.flush(),
//
Expand Down
12 changes: 12 additions & 0 deletions src/tests/classes/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest';

const __origAppPkgName__ = $env.get('APP_PKG_NAME', { type: 'unknown' });
const __origAppBaseURL__ = $env.get('APP_BASE_URL', { type: 'unknown' });
const __origAppRootR2OriginURL__ = $env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppRootR2BaseURL__ = $env.get('APP_ROOT_R2_BASE_URL', { type: 'unknown' });
const __origAppR2OriginURL__ = $env.get('APP_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppR2BaseURL__ = $env.get('APP_R2_BASE_URL', { type: 'unknown' });
const __origAppBrandProps__ = $env.get('APP_BRAND_PROPS', { type: 'unknown' });
Expand All @@ -19,6 +21,8 @@ describe('Logger', async () => {
beforeAll(async () => {
$env.set('APP_PKG_NAME', '@clevercanyon/x.tld');
$env.set('APP_BASE_URL', 'https://x.tld/base/');
$env.set('APP_ROOT_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_ROOT_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_BRAND_PROPS', { type: 'site' });
Expand All @@ -27,6 +31,8 @@ describe('Logger', async () => {
afterAll(async () => {
$env.set('APP_PKG_NAME', __origAppPkgName__);
$env.set('APP_BASE_URL', __origAppBaseURL__);
$env.set('APP_ROOT_R2_ORIGIN_URL', __origAppRootR2OriginURL__);
$env.set('APP_ROOT_R2_BASE_URL', __origAppRootR2BaseURL__);
$env.set('APP_R2_ORIGIN_URL', __origAppR2OriginURL__);
$env.set('APP_R2_BASE_URL', __origAppR2BaseURL__);
$env.set('APP_BRAND_PROPS', __origAppBrandProps__);
Expand All @@ -40,6 +46,12 @@ describe('Logger', async () => {
$app.hasBaseURL.flush(),
$app.baseURL.flush(),
//
$app.hasRootR2OriginURL.flush(),
$app.rootR2OriginURL.flush(),
//
$app.hasRootR2BaseURL.flush(),
$app.rootR2BaseURL.flush(),
//
$app.hasR2OriginURL.flush(),
$app.r2OriginURL.flush(),
//
Expand Down
12 changes: 12 additions & 0 deletions src/tests/preact/apis/iso/hydratively-render-spa.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';

const __origAppPkgName__ = $env.get('APP_PKG_NAME', { type: 'unknown' });
const __origAppBaseURL__ = $env.get('APP_BASE_URL', { type: 'unknown' });
const __origAppRootR2OriginURL__ = $env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppRootR2BaseURL__ = $env.get('APP_ROOT_R2_BASE_URL', { type: 'unknown' });
const __origAppR2OriginURL__ = $env.get('APP_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppR2BaseURL__ = $env.get('APP_R2_BASE_URL', { type: 'unknown' });
const __origAppBrandProps__ = $env.get('APP_BRAND_PROPS', { type: 'unknown' });
Expand All @@ -17,6 +19,8 @@ describe('$preact.iso.hydrativelyRenderSPA() [web]', async () => {
beforeAll(async () => {
$env.set('APP_PKG_NAME', '@clevercanyon/x.tld');
$env.set('APP_BASE_URL', 'https://x.tld/base/');
$env.set('APP_ROOT_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_ROOT_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_BRAND_PROPS', { type: 'site' });
Expand All @@ -25,6 +29,8 @@ describe('$preact.iso.hydrativelyRenderSPA() [web]', async () => {
afterAll(async () => {
$env.set('APP_PKG_NAME', __origAppPkgName__);
$env.set('APP_BASE_URL', __origAppBaseURL__);
$env.set('APP_ROOT_R2_ORIGIN_URL', __origAppRootR2OriginURL__);
$env.set('APP_ROOT_R2_BASE_URL', __origAppRootR2BaseURL__);
$env.set('APP_R2_ORIGIN_URL', __origAppR2OriginURL__);
$env.set('APP_R2_BASE_URL', __origAppR2BaseURL__);
$env.set('APP_BRAND_PROPS', __origAppBrandProps__);
Expand All @@ -38,6 +44,12 @@ describe('$preact.iso.hydrativelyRenderSPA() [web]', async () => {
$app.hasBaseURL.flush(),
$app.baseURL.flush(),
//
$app.hasRootR2OriginURL.flush(),
$app.rootR2OriginURL.flush(),
//
$app.hasRootR2BaseURL.flush(),
$app.rootR2BaseURL.flush(),
//
$app.hasR2OriginURL.flush(),
$app.r2OriginURL.flush(),
//
Expand Down
12 changes: 12 additions & 0 deletions src/tests/preact/apis/iso/prerender-spa-404.cfw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest';

const __origAppPkgName__ = $env.get('APP_PKG_NAME', { type: 'unknown' });
const __origAppBaseURL__ = $env.get('APP_BASE_URL', { type: 'unknown' });
const __origAppRootR2OriginURL__ = $env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppRootR2BaseURL__ = $env.get('APP_ROOT_R2_BASE_URL', { type: 'unknown' });
const __origAppR2OriginURL__ = $env.get('APP_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppR2BaseURL__ = $env.get('APP_R2_BASE_URL', { type: 'unknown' });
const __origAppBrandProps__ = $env.get('APP_BRAND_PROPS', { type: 'unknown' });
Expand All @@ -17,6 +19,8 @@ describe('$preact.iso.prerenderSPA() [404-cfw]', async () => {
beforeAll(async () => {
$env.set('APP_PKG_NAME', '@clevercanyon/x.tld');
$env.set('APP_BASE_URL', 'https://x.tld/base/');
$env.set('APP_ROOT_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_ROOT_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_BRAND_PROPS', { type: 'site' });
Expand All @@ -25,6 +29,8 @@ describe('$preact.iso.prerenderSPA() [404-cfw]', async () => {
afterAll(async () => {
$env.set('APP_PKG_NAME', __origAppPkgName__);
$env.set('APP_BASE_URL', __origAppBaseURL__);
$env.set('APP_ROOT_R2_ORIGIN_URL', __origAppRootR2OriginURL__);
$env.set('APP_ROOT_R2_BASE_URL', __origAppRootR2BaseURL__);
$env.set('APP_R2_ORIGIN_URL', __origAppR2OriginURL__);
$env.set('APP_R2_BASE_URL', __origAppR2BaseURL__);
$env.set('APP_BRAND_PROPS', __origAppBrandProps__);
Expand All @@ -38,6 +44,12 @@ describe('$preact.iso.prerenderSPA() [404-cfw]', async () => {
$app.hasBaseURL.flush(),
$app.baseURL.flush(),
//
$app.hasRootR2OriginURL.flush(),
$app.rootR2OriginURL.flush(),
//
$app.hasRootR2BaseURL.flush(),
$app.rootR2BaseURL.flush(),
//
$app.hasR2OriginURL.flush(),
$app.r2OriginURL.flush(),
//
Expand Down
12 changes: 12 additions & 0 deletions src/tests/preact/apis/iso/prerender-spa-for-web-fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest';

const __origAppPkgName__ = $env.get('APP_PKG_NAME', { type: 'unknown' });
const __origAppBaseURL__ = $env.get('APP_BASE_URL', { type: 'unknown' });
const __origAppRootR2OriginURL__ = $env.get('APP_ROOT_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppRootR2BaseURL__ = $env.get('APP_ROOT_R2_BASE_URL', { type: 'unknown' });
const __origAppR2OriginURL__ = $env.get('APP_R2_ORIGIN_URL', { type: 'unknown' });
const __origAppR2BaseURL__ = $env.get('APP_R2_BASE_URL', { type: 'unknown' });
const __origAppBrandProps__ = $env.get('APP_BRAND_PROPS', { type: 'unknown' });
Expand All @@ -21,6 +23,8 @@ describe('$preact.iso.prerenderSPA() [web-fixture]', async () => {
beforeAll(async () => {
$env.set('APP_PKG_NAME', '@clevercanyon/x.tld');
$env.set('APP_BASE_URL', 'https://x.tld/base/');
$env.set('APP_ROOT_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_ROOT_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_R2_ORIGIN_URL', 'https://r2.tld');
$env.set('APP_R2_BASE_URL', 'https://r2.tld/base/');
$env.set('APP_BRAND_PROPS', { type: 'site' });
Expand All @@ -29,6 +33,8 @@ describe('$preact.iso.prerenderSPA() [web-fixture]', async () => {
afterAll(async () => {
$env.set('APP_PKG_NAME', __origAppPkgName__);
$env.set('APP_BASE_URL', __origAppBaseURL__);
$env.set('APP_ROOT_R2_ORIGIN_URL', __origAppRootR2OriginURL__);
$env.set('APP_ROOT_R2_BASE_URL', __origAppRootR2BaseURL__);
$env.set('APP_R2_ORIGIN_URL', __origAppR2OriginURL__);
$env.set('APP_R2_BASE_URL', __origAppR2BaseURL__);
$env.set('APP_BRAND_PROPS', __origAppBrandProps__);
Expand All @@ -42,6 +48,12 @@ describe('$preact.iso.prerenderSPA() [web-fixture]', async () => {
$app.hasBaseURL.flush(),
$app.baseURL.flush(),
//
$app.hasRootR2OriginURL.flush(),
$app.rootR2OriginURL.flush(),
//
$app.hasRootR2BaseURL.flush(),
$app.rootR2BaseURL.flush(),
//
$app.hasR2OriginURL.flush(),
$app.r2OriginURL.flush(),
//
Expand Down
Loading

0 comments on commit c0a08d1

Please sign in to comment.