@toddledev/ssr
Advanced tools
Comparing version 0.0.2-alpha.13 to 0.0.2-alpha.14
import type { PageComponent } from '@toddledev/core/dist/component/component.types'; | ||
import { FormulaContext, ToddleServerEnv } from '@toddledev/core/dist/formula/formula'; | ||
import { ProjectFiles } from '../ssr.types'; | ||
/** | ||
@@ -7,3 +8,3 @@ * Builds a FormulaContext that can be used to evaluate formulas for a page component | ||
*/ | ||
export declare const getPageFormulaContext: ({ branchName, component, req, logErrors, }: { | ||
export declare const getPageFormulaContext: ({ branchName, component, req, logErrors, files, }: { | ||
branchName: string; | ||
@@ -13,2 +14,3 @@ component: PageComponent; | ||
logErrors: boolean; | ||
files: ProjectFiles; | ||
}) => FormulaContext; | ||
@@ -15,0 +17,0 @@ export declare const serverEnv: ({ branchName, req, logErrors, }: { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serverEnv = exports.getPageFormulaContext = void 0; | ||
const formula_1 = require("@toddledev/core/dist/formula/formula"); | ||
const formulaTypes_1 = require("@toddledev/core/dist/formula/formulaTypes"); | ||
const collections_1 = require("@toddledev/core/dist/utils/collections"); | ||
const util_1 = require("@toddledev/core/dist/utils/util"); | ||
const libFormulas = __importStar(require("@toddledev/std-lib/dist/formulas")); | ||
const routing_1 = require("../routing/routing"); | ||
@@ -14,5 +49,9 @@ const cookies_1 = require("./cookies"); | ||
*/ | ||
const getPageFormulaContext = ({ branchName, component, req, logErrors, }) => { | ||
const getPageFormulaContext = ({ branchName, component, req, logErrors, files, }) => { | ||
const env = (0, exports.serverEnv)({ req, branchName, logErrors }); | ||
const { searchParamsWithDefaults, hash, combinedParams, url } = getParameters({ component, req }); | ||
const coreFormulas = Object.fromEntries(Object.entries(libFormulas).map(([name, module]) => [ | ||
'@toddle/' + name, | ||
module.default, | ||
])); | ||
const formulaContext = { | ||
@@ -41,2 +80,17 @@ data: { | ||
env, | ||
toddle: { | ||
getFormula: (name) => coreFormulas[name], | ||
getCustomFormula: (name, packageName) => { | ||
let formula; | ||
if ((0, util_1.isDefined)(packageName)) { | ||
formula = files.packages?.[packageName]?.formulas?.[name]; | ||
} | ||
else { | ||
formula = files.formulas?.[name]; | ||
} | ||
if (formula && (0, formulaTypes_1.isToddleFormula)(formula)) { | ||
return formula; | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -43,0 +97,0 @@ formulaContext.data.Variables = (0, collections_1.mapValues)(component.variables, ({ initialValue }) => { |
{ | ||
"name": "@toddledev/ssr", | ||
"version": "0.0.2-alpha.13", | ||
"version": "0.0.2-alpha.14", | ||
"license": "Apache-2.0", | ||
@@ -19,9 +19,6 @@ "homepage": "https://github.com/toddledev/toddle", | ||
"dependencies": { | ||
"@toddledev/core": "0.0.2-alpha.12", | ||
"@toddledev/core": "0.0.2-alpha.14", | ||
"cookie": "1.0.2", | ||
"xss": "1.0.15" | ||
}, | ||
"description": "[npm](https://www.npmjs.com/package/@toddledev/ssr)", | ||
"devDependencies": {}, | ||
"author": "" | ||
} | ||
} |
@@ -7,5 +7,11 @@ import type { PageComponent } from '@toddledev/core/dist/component/component.types' | ||
} from '@toddledev/core/dist/formula/formula' | ||
import { | ||
isToddleFormula, | ||
PluginFormula, | ||
} from '@toddledev/core/dist/formula/formulaTypes' | ||
import { mapValues } from '@toddledev/core/dist/utils/collections' | ||
import { isDefined } from '@toddledev/core/dist/utils/util' | ||
import * as libFormulas from '@toddledev/std-lib/dist/formulas' | ||
import { getPathSegments } from '../routing/routing' | ||
import { ProjectFiles } from '../ssr.types' | ||
import { getRequestCookies } from './cookies' | ||
@@ -23,2 +29,3 @@ import { escapeSearchParameters } from './request' | ||
logErrors, | ||
files, | ||
}: { | ||
@@ -29,2 +36,3 @@ branchName: string | ||
logErrors: boolean | ||
files: ProjectFiles | ||
}): FormulaContext => { | ||
@@ -35,2 +43,8 @@ const env = serverEnv({ req, branchName, logErrors }) | ||
) | ||
const coreFormulas = Object.fromEntries( | ||
Object.entries(libFormulas).map(([name, module]) => [ | ||
'@toddle/' + name, | ||
module.default as any, | ||
]), | ||
) | ||
const formulaContext: FormulaContext = { | ||
@@ -59,2 +73,18 @@ data: { | ||
env, | ||
toddle: { | ||
getFormula: (name: string) => coreFormulas[name], | ||
getCustomFormula: (name: string, packageName: string | undefined) => { | ||
let formula: PluginFormula<string> | undefined | ||
if (isDefined(packageName)) { | ||
formula = files.packages?.[packageName]?.formulas?.[name] | ||
} else { | ||
formula = files.formulas?.[name] | ||
} | ||
if (formula && isToddleFormula(formula)) { | ||
return formula | ||
} | ||
}, | ||
}, | ||
} | ||
@@ -61,0 +91,0 @@ formulaContext.data.Variables = mapValues( |
Sorry, the diff of this file is not supported yet
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
98520
52
2100
362
20
5
20
3
20
+ Added@toddledev/core@0.0.2-alpha.14(transitive)
- Removed@toddledev/core@0.0.2-alpha.12(transitive)