diff --git a/core/ts/recipe/Chef.ts b/core/ts/recipe/Chef.ts index ebd32d8b..aa7beeba 100644 --- a/core/ts/recipe/Chef.ts +++ b/core/ts/recipe/Chef.ts @@ -23,7 +23,7 @@ export class Chef { return; } //log.groupCollapsed('executing recipe...', recipe.$meta); - log('|-->...| executing recipe: ', recipe.$meta ?? ''); + log('|-->...| executing recipe: ', recipe); const plan = new Parser(recipe); // `store` preparation await StoreCook.execute(runtime, arc, plan.stores); diff --git a/pkg/Library/Core/arcs.js b/pkg/Library/Core/arcs.js index af5d6ce7..38853a33 100644 --- a/pkg/Library/Core/arcs.js +++ b/pkg/Library/Core/arcs.js @@ -1078,7 +1078,7 @@ var Chef = class { log6.error("`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited."); return; } - log6("|-->...| executing recipe: ", recipe.$meta ?? ""); + log6("|-->...| executing recipe: ", recipe); const plan = new Parser(recipe); await StoreCook.execute(runtime, arc, plan.stores); await ParticleCook.execute(runtime, arc, plan.particles); diff --git a/pkg/Library/Core/arcs.js.map b/pkg/Library/Core/arcs.js.map index b3919ae7..7be69c37 100644 --- a/pkg/Library/Core/arcs.js.map +++ b/pkg/Library/Core/arcs.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../core/js/core/EventEmitter.js", "../../../core/js/utils/types.js", "../../../core/js/utils/log.js", "../../../core/js/core/Arc.js", "../../../core/js/utils/object.js", "../../../core/js/utils/rand.js", "../../../core/js/core/Decorator.js", "../../../core/js/core/Host.js", "../../../core/js/core/Store.js", "../../../core/js/utils/id.js", "../../../core/js/Runtime.js", "../../../core/js/recipe/RecipeParser.js", "../../../core/js/utils/matching.js", "../../../core/js/recipe/StoreCook.js", "../../../core/js/recipe/ParticleCook.js", "../../../core/js/recipe/Chef.js", "../../../core/js/isolation/code.js", "../../../core/js/utils/paths.js", "../../../core/js/utils/utils.js", "../../../core/js/utils/date.js", "../../../core/js/utils/task.js", "../../../core/src/arcs.ts"], - "sourcesContent": ["/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport class EventEmitter {\n // map of event name to listener array\n listeners = {};\n getEventListeners(eventName) {\n return this.listeners[eventName] || (this.listeners[eventName] = []);\n }\n fire(eventName, ...args) {\n const listeners = this.getEventListeners(eventName);\n if (listeners?.forEach) {\n listeners.forEach(listener => listener(...args));\n }\n }\n listen(eventName, listener, listenerName) {\n const listeners = this.getEventListeners(eventName);\n listeners.push(listener);\n listener._name = listenerName || '(unnamed listener)';\n return listener;\n }\n unlisten(eventName, listener) {\n const list = this.getEventListeners(eventName);\n const index = (typeof listener === 'string') ? list.findIndex(l => l._name === listener) : list.indexOf(listener);\n if (index >= 0) {\n list.splice(index, 1);\n }\n else {\n console.warn('failed to unlisten from', eventName);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const logKinds = ['log', 'group', 'groupCollapsed', 'groupEnd', 'dir'];\nexport const errKinds = ['warn', 'error'];\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logKinds, errKinds } from './types.js';\nconst { fromEntries } = Object;\nconst _logFactory = (enable, preamble, bg, color, kind = 'log') => {\n if (typeof enable === 'string') {\n enable = logFactory.flags[enable];\n }\n if (!enable) {\n return () => { };\n }\n if (kind === 'dir') {\n return console.dir.bind(console);\n }\n const style = `background: ${bg || 'gray'}; color: ${color || 'white'}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;\n return console[kind].bind(console, `%c${preamble}`, style);\n};\nexport const logFactory = (enable, preamble, bg = '', color = '') => {\n const debugLoggers = fromEntries(logKinds.map(kind => [kind, _logFactory(enable, preamble, bg, color, kind)]));\n const errorLoggers = fromEntries(errKinds.map(kind => [kind, _logFactory(true, preamble, bg, color, kind)]));\n const loggers = { ...debugLoggers, ...errorLoggers };\n // Inject `log` as default, keeping all loggers available to be invoked by name.\n const log = loggers.log;\n Object.assign(log, loggers);\n return log;\n};\nlogFactory.flags = globalThis.config?.logFlags || {};\n", "/**\n * @license\n * Copyright (c) 2022 Google LLC All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\nimport { EventEmitter } from './EventEmitter.js';\nimport { logFactory } from '../utils/log.js';\nconst customLogFactory = (id) => logFactory(logFactory.flags.arc, `Arc (${id})`, 'slateblue');\nconst { assign, create } = Object;\nconst entries = (o) => Object.entries(o ?? Object);\nconst keys = (o) => Object.keys(o ?? Object);\nconst values = (o) => Object.values(o ?? Object);\nconst nob = () => create(null);\nexport class Arc extends EventEmitter {\n log;\n id;\n meta;\n stores;\n hosts;\n surface;\n composer;\n hostService;\n constructor(id, meta, surface) {\n super();\n this.id = id;\n this.meta = meta;\n this.surface = surface;\n this.hosts = nob();\n this.stores = nob();\n this.log = customLogFactory(id);\n }\n async addHost(host, surface) {\n // to support hosts we need a composer\n await this.ensureComposer();\n // bookkeep\n this.hosts[host.id] = host;\n host.arc = this;\n // TODO(sjmiles): support per host surfacing?\n //await host.bindToSurface(surface ?? this.surface);\n // begin work\n this.updateHost(host);\n return host;\n }\n async ensureComposer() {\n if (!this.composer && this.surface) {\n // create composer\n this.composer = await this.surface.createComposer('root');\n // pipeline for events from composer to this.onevent\n // TODO(sjmiles): use 'bind' to avoid a closure and improve the stack trace\n this.composer.onevent = this.onevent.bind(this);\n }\n }\n rerender() {\n values(this.hosts).forEach(h => h.rerender());\n }\n removeHost(id) {\n this.hosts[id]?.detach();\n delete this.hosts[id];\n }\n addStore(storeId, store) {\n if (store && !this.stores[storeId]) {\n this.stores[storeId] = store;\n store.listen('change', () => this.storeChanged(storeId, store), this.id);\n }\n }\n removeStore(storeId) {\n const store = this.stores[storeId];\n if (store) {\n store.unlisten('change', this.id);\n }\n delete this.stores[storeId];\n }\n // TODO(sjmiles): 2nd param is used in overrides, make explicit\n storeChanged(storeId, store) {\n this.log(`storeChanged: \"${storeId}\"`);\n const isBound = inputs => inputs && inputs.some(input => input && (values(input)[0] == storeId || keys(input)[0] == storeId));\n values(this.hosts).forEach(host => {\n const inputs = host.meta?.inputs;\n if (inputs === '*' || isBound(inputs)) {\n this.log(`host \"${host.id}\" has interest in \"${storeId}\"`);\n // TODO(sjmiles): we only have to update inputs for storeId, we lose efficiency here\n this.updateHost(host);\n }\n });\n this.fire('store-changed', storeId);\n }\n updateParticleMeta(hostId, meta) {\n const host = this.hosts[hostId];\n host.meta = meta;\n this.updateHost(host);\n }\n updateHost(host) {\n host.inputs = this.computeInputs(host);\n }\n // TODO(sjmiles): debounce? (update is sync-debounced already)\n // complement to `assignOutputs`\n computeInputs(host) {\n const inputs = nob();\n const inputBindings = host.meta?.inputs;\n if (inputBindings === '*') {\n // TODO(sjmiles): we could make the contract that the bindAll inputs are\n // names (or names + meta) only. The Particle could look up values via\n // service (to reduce throughput requirements)\n entries(this.stores).forEach(([name, store]) => inputs[name] = store.pojo);\n }\n else {\n const staticInputs = host.meta?.staticInputs;\n assign(inputs, staticInputs);\n if (inputBindings) {\n inputBindings.forEach(input => input && this.computeInput(entries(input)[0], inputs));\n this.log(`computeInputs(${host.id}) =`, inputs);\n }\n }\n return inputs;\n }\n computeInput([name, binding], inputs) {\n const storeName = binding || name;\n const store = this.stores[storeName];\n if (store) {\n inputs[name] = store.pojo;\n }\n else {\n // TODO(sjmiles): is this ok or not?\n //this.log.warn(`computeInput: \"${storeName}\" (bound to \"${name}\") not found`);\n }\n }\n // complement to `computeInputs`\n assignOutputs({ id, meta }, outputs) {\n const names = keys(outputs);\n if (meta?.outputs && names.length) {\n names.forEach(name => this.assignOutput(name, outputs[name], meta.outputs));\n this.log(`[end][${id}] assignOutputs:`, outputs);\n }\n }\n assignOutput(name, output, outputs) {\n if (output !== undefined) {\n const binding = this.findOutputByName(outputs, name) || name;\n const store = this.stores[binding];\n if (!store) {\n if (outputs?.[name]) {\n this.log.warn(`assignOutputs: no \"${binding}\" store for output \"${name}\"`);\n }\n }\n else {\n // Note: users can mess up output data in any way they see fit, so we should\n // probably invent `outputCleansing`.\n this.log(`assignOutputs: \"${name}\" is dirty, updating Store \"${binding}\"`, output);\n store.data = output;\n }\n }\n }\n findOutputByName(outputs, name) {\n const output = outputs?.find(output => keys(output || 0)[0] === name);\n if (output) {\n return values(output)[0];\n }\n }\n async render(packet) {\n if (this.composer) {\n this.composer.render({ ...packet, arcid: this.id });\n }\n else {\n //this.log.low('render called, but composer is null', packet);\n }\n }\n onevent(pid, eventlet) {\n const host = this.hosts[pid];\n if (host) {\n host.handleEvent(eventlet);\n }\n }\n async service(host, request) {\n let result = await this.surface?.service(request);\n if (result === undefined) {\n result = this.hostService?.(host, request);\n }\n return result;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/*\n * update the fields of `obj` with the fields of `data`,\n * perturbing `obj` as little as possible (since it might be a magic proxy thing\n * like an Automerge document)\n */\nexport const shallowUpdate = (obj, data) => {\n let result = data;\n if (!data) {\n //\n }\n else if (Array.isArray(data)) {\n if (!Array.isArray(obj)) {\n // TODO(sjmiles): eek, very perturbing to obj\n obj = [];\n }\n for (let i = 0; i < data.length; i++) {\n const value = data[i];\n if (obj[i] !== value) {\n obj[i] = value;\n }\n }\n const overage = obj.length - data.length;\n if (overage > 0) {\n obj.splice(data.length, overage);\n }\n }\n else if (typeof data === 'object') {\n result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n const seen = {};\n // for each key in input data ...\n Object.keys(data).forEach(key => {\n // copy that data into output\n result[key] = data[key];\n // remember the key\n seen[key] = true;\n });\n // for each key in the output data...\n Object.keys(result).forEach(key => {\n // if this key was not in the input, remove it\n if (!seen[key]) {\n delete result[key];\n }\n });\n }\n return result;\n};\nexport const shallowMerge = (obj, data) => {\n if (data == null) {\n return null;\n }\n if (typeof data === 'object') {\n const result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n Object.keys(data).forEach(key => result[key] = data[key]);\n return result;\n }\n return data;\n};\nexport function deepCopy(datum) {\n if (!datum) {\n return datum;\n }\n else if (Array.isArray(datum)) {\n // This is trivially type safe but tsc needs help\n return datum.map(element => deepCopy(element));\n }\n else if (typeof datum === 'object') {\n const clone = Object.create(null);\n Object.entries(datum).forEach(([key, value]) => {\n clone[key] = deepCopy(value);\n });\n return clone;\n }\n else {\n return datum;\n }\n}\nexport const deepEqual = (a, b) => {\n const type = typeof a;\n // must be same type to be equal\n if (type !== typeof b) {\n return false;\n }\n // we are `deep` because we recursively study object types\n if (type === 'object' && a && b) {\n const aProps = Object.getOwnPropertyNames(a);\n const bProps = Object.getOwnPropertyNames(b);\n // equal if same # of props, and no prop is not deepEqual\n return (aProps.length == bProps.length) && !aProps.some(name => !deepEqual(a[name], b[name]));\n }\n // finally, perform simple comparison\n return (a === b);\n};\nexport const deepUndefinedToNull = (obj) => {\n if (obj === undefined) {\n return null;\n }\n if (obj && (typeof obj === 'object')) {\n // we are `deep` because we recursively study object types\n const props = Object.getOwnPropertyNames(obj);\n props.forEach(name => {\n const prop = obj[name];\n if (prop === undefined) {\n delete obj[name];\n //obj[name] = null;\n }\n else {\n deepUndefinedToNull(prop);\n }\n });\n }\n return obj;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nconst { floor, pow, random } = Math;\n// random n-digit number\nexport const key = (digits) => floor((1 + random() * 9) * pow(10, digits - 1));\n// random integer from [0..range)\nexport const irand = (range) => floor(random() * range);\n// random element from array\nexport const arand = (array) => array[irand(array.length)];\n// test if event has occured, where `probability` is between [0..1]\nexport const prob = (probability) => Boolean(random() < probability);\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepCopy } from '../utils/object.js';\nconst log = logFactory(logFactory.flags.decorator, 'Decorator', 'plum');\nconst { values, entries } = Object;\nconst opaqueData = {};\nexport const Decorator = {\n setOpaqueData(name, data) {\n opaqueData[name] = data; //deepCopy(data);\n return name;\n },\n getOpaqueData(name) {\n return opaqueData[name];\n },\n maybeDecorateModel(model, particle) {\n if (model && !Array.isArray(model)) {\n // for each item in model, regardless of key\n values(model).forEach((item) => {\n // is an object?\n if (item && (typeof item === 'object')) {\n // are there sub-models\n if (item['models']) {\n // the decorate this item\n log('applying decorator(s) to list:', item);\n this.maybeDecorateItem(item, particle);\n }\n else {\n // otherwise, check if there are sub-items to decorate\n if (model?.filter || model?.decorator || model?.collateBy) {\n log('scanning for lists in sub-model:', item);\n this.maybeDecorateModel(item, particle);\n }\n }\n }\n });\n }\n // possibly decorated model\n return model;\n },\n maybeDecorateItem(item, particle) {\n let models = (typeof item.models === 'string') ? this.getOpaqueData(item.models) : item.models;\n if (models) {\n // do a decorator\n models = maybeDecorate(models, item.decorator, particle);\n // do a filter\n models = maybeFilter(models, item.filter, particle.impl);\n // do a collator\n models = maybeCollateBy(models, item);\n // mutate items\n item.models = models;\n //console.log(JSON.stringify(models, null, ' '));\n }\n },\n};\nconst maybeDecorate = (models, decorator, particle) => {\n decorator = particle.impl[decorator] ?? decorator;\n const { inputs, state } = particle.internal;\n if (decorator) {\n // TODO(cromwellian): Could be expensive to do everything, store responsibility?\n const immutableInputs = Object.freeze(deepCopy(inputs));\n // we don't want the decorator to have access to mutable globals\n const immutableState = Object.freeze(deepCopy(state));\n // models become decorous\n models = models.map(model => {\n // use previously mutated data or initialize\n // TODO(cromwellian): I'd like to do Object.freeze() here, also somehow not mutate the models inplace\n // Possibly have setOpaqueData wrap the data so the privateData lives on the wrapper + internal immutable data\n model.privateData = model.privateData || {};\n // TODO(cromwellian): also could be done once during setOpaqueData() if we can track privateData differently\n const immutableModel = Object.freeze(deepCopy(model));\n const decorated = decorator(immutableModel, immutableInputs, immutableState);\n // set new privateData from returned\n model.privateData = decorated.privateData;\n return { ...decorated, ...model, };\n });\n // sort (possible that all values undefined)\n models.sort(sortByLc('sortKey'));\n log('decoration was performed');\n }\n //models.forEach(model => delete model.privateData);\n return models;\n};\nconst maybeFilter = (models, filter, impl) => {\n filter = impl[filter] ?? filter;\n if (filter && models) {\n // models become filtrated\n models = models.filter(filter);\n }\n return models;\n};\nconst maybeCollateBy = (models, item) => {\n // construct requested sub-lists\n entries(item).forEach(([name, collator]) => {\n // generate named collations for items of the form `[name]: {collateBy}`\n if (collator?.['collateBy']) {\n // group the models into buckets based on the model-field named by `collateBy`\n const collation = collate(models, collator['collateBy']);\n models = collationToRenderModels(collation, name, collator['$template']);\n }\n });\n return models;\n};\nconst sortByLc = key => (a, b) => sort(String(a[key]).toLowerCase(), String(b[key]).toLowerCase());\n//const sortBy = key => (a, b) => sort(a[key], b[key]);\nconst sort = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst collate = (models, collateBy) => {\n const collation = {};\n models.forEach(model => {\n const keyValue = model[collateBy];\n if (keyValue) {\n const category = collation[keyValue] || (collation[keyValue] = []);\n category.push(model);\n }\n });\n return collation;\n};\nconst collationToRenderModels = (collation, name, $template) => {\n return entries(collation).map(([key, models]) => ({\n key,\n [name]: { models, $template },\n single: !(models['length'] !== 1),\n ...models?.[0]\n }));\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepEqual, deepCopy } from '../utils/object.js';\nimport { arand } from '../utils/rand.js';\nimport { EventEmitter } from './EventEmitter.js';\nimport { Decorator } from './Decorator.js';\nconst { entries, keys } = Object;\nconst customLogFactory = (id) => logFactory(logFactory.flags.host, `Host (${id})`, arand(['#5a189a', '#51168b', '#48137b', '#6b2fa4', '#7b46ae', '#3f116c']));\n/**\n * Host owns metadata (e.g. `id`, `container`) that its Particle is not allowed to access.\n * Host knows how to talk, asynchronously, to its Particle (potentially using a bus).\n**/\n/* TODO(sjmiles):\nUpdate Cycle Documented Briefly\n1. when a Store changes it invokes it's listeners\n2. when an Arc hears a Store change, it updates Hosts bound to the Store\n3. Arc updates Host by creating an `inputs` object from Stores and metadata\n - ignores fact inputs are accumulated\n - ignores information about which Store has updated\n4. `inputs` object is assigned to `hosts.inputs` \uD83D\uDE43\n5. Host does an expensive `deepEqual` equality check. Turning on `host` logging should reveal `this.log('inputs are not interesting, skipping update');` if data is caught in this trap\n - we can use reference testing here if we are more careful\n about using immutable data\n6. the particle.inputs are assigned (but is really a *merge*)\n*/\nexport class Host extends EventEmitter {\n arc;\n id;\n lastOutput;\n lastPacket;\n lastRenderModel;\n log;\n meta;\n particle;\n constructor(id) {\n super();\n this.log = customLogFactory(id);\n this.id = id;\n }\n onevent(eventlet) {\n this.arc?.onevent(eventlet);\n this.fire('eventlet', eventlet);\n }\n // Particle and ParticleMeta are separate, host specifically integrates these on behalf of Particle\n installParticle(particle, meta) {\n if (this.particle) {\n this.detachParticle();\n }\n if (particle) {\n this.particle = particle;\n this.meta = meta || this.meta;\n }\n }\n get container() {\n return this.meta?.container || 'root';\n }\n detach() {\n this.detachParticle();\n this.arc = null;\n }\n detachParticle() {\n if (this.particle) {\n this.render({ $clear: true });\n this.particle = null;\n this.meta = null;\n }\n }\n async service(request) {\n if (request?.decorate) {\n return Decorator.maybeDecorateModel(request.model, this.particle);\n }\n return this.arc?.service(this, request);\n }\n output(outputModel, renderModel) {\n if (outputModel) {\n this.lastOutput = outputModel;\n this.arc?.assignOutputs(this, outputModel);\n this.fire('output', outputModel);\n }\n if (this.template) {\n Decorator.maybeDecorateModel(renderModel, this.particle);\n this.lastRenderModel = { ...renderModel };\n this.render(renderModel);\n }\n }\n rerender() {\n // does not re-render Frame/Slot content\n // you probably want Arc::rerender\n if (this.lastRenderModel) {\n this.render(this.lastRenderModel);\n }\n }\n render(model) {\n const { id, container, template } = this;\n const content = { model, template };\n const packet = { id, container, content };\n this.fire('render', packet);\n this.arc?.render(packet);\n this.lastPacket = packet;\n }\n set inputs(inputs) {\n if (this.particle && inputs) {\n const lastInputs = this.particle.internal.inputs;\n if (this.dirtyCheck(inputs, lastInputs, this.lastOutput)) {\n this.particle.inputs = deepCopy({ ...this.meta?.staticInputs, ...inputs });\n this.fire('inputs-changed');\n }\n else {\n this.log('inputs are uninteresting, skipping update');\n }\n }\n }\n dirtyCheck(inputs, lastInputs, lastOutput) {\n const dirtyBits = ([n, v]) => (lastOutput?.[n] && !deepEqual(lastOutput[n], v))\n || !deepEqual(lastInputs?.[n], v);\n return !lastInputs\n || entries(inputs).length !== this.lastInputsLength(lastInputs)\n || entries(inputs).some(dirtyBits);\n }\n lastInputsLength(lastInputs) {\n return keys(lastInputs).filter(key => !this.meta?.staticInputs?.[key] && key !== 'eventlet').length;\n }\n get config() {\n return this.particle?.config;\n }\n get template() {\n return this.config?.template;\n }\n invalidate() {\n this.particle?.invalidate();\n }\n handleEvent(eventlet) {\n return this.particle?.handleEvent(eventlet);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { EventEmitter } from './EventEmitter.js';\nconst { create, keys } = Object;\nconst { stringify, parse } = JSON;\nexport class DataStore extends EventEmitter {\n privateData;\n constructor() {\n super();\n }\n setPrivateData(data) {\n this.privateData = data;\n }\n set data(data) {\n this.setPrivateData(data);\n }\n get data() {\n return this.privateData;\n }\n toString() {\n return this.pretty;\n }\n get isObject() {\n return this.data && typeof this.data === 'object';\n }\n get pojo() {\n return this.data;\n }\n get json() {\n return stringify(this.data);\n }\n set json(json) {\n let value = null;\n try {\n value = parse(json);\n }\n catch (x) {\n //\n }\n this.data = value;\n }\n get pretty() {\n const sorted = {};\n const pojo = this.pojo;\n keys(pojo).sort().forEach(key => sorted[key] = pojo[key]);\n return stringify(sorted, null, ' ');\n }\n}\nclass ObservableStore extends DataStore {\n change(mutator) {\n mutator(this);\n this.doChange();\n }\n doChange() {\n this.fire('change', this);\n this.onChange(this);\n }\n onChange(store) {\n // override\n }\n set data(data) {\n this.change(self => self.setPrivateData(data));\n }\n // TODO(sjmiles): one of the compile/build/bundle tools\n // evacipates the inherited getter, so we clone it\n get data() {\n return this['privateData'];\n }\n set(key, value) {\n if (!this.data) {\n this.setPrivateData(create(null));\n }\n if (value !== undefined) {\n this.change(self => self.data[key] = value);\n }\n else {\n this.delete(key);\n }\n }\n delete(key) {\n this.change(doc => delete doc.data[key]);\n }\n}\nclass PersistableStore extends ObservableStore {\n meta;\n constructor(meta) {\n super();\n this.meta = { ...meta };\n }\n toString() {\n return `${JSON.stringify(this.meta, null, ' ')}, ${this.pretty}`;\n }\n get tags() {\n return this.meta.tags ?? (this.meta.tags = []);\n }\n is(...tags) {\n // true if every member of `tags` is also in `this.tags`\n return tags.every(tag => this.tags.includes(tag));\n }\n isCollection() {\n return this.meta.type?.[0] === '[';\n }\n shouldPersist() {\n return this.is('persisted') && !this.is('volatile');\n }\n async doChange() {\n // do not await\n this.persist();\n return super.doChange();\n }\n // TODO(sjmiles): as of now the persist/restore methods\n // are bound in Runtime:addStore\n async persist() {\n }\n async restore( /*value: any*/) {\n }\n // delete() {\n // this.persistor?.remove(this);\n // }\n save() {\n return this.json;\n }\n load(serial, defaultValue) {\n let value = defaultValue;\n try {\n if (serial) {\n value = parse(serial);\n }\n }\n catch (x) {\n //\n }\n if (value !== undefined) {\n this.data = value;\n }\n }\n}\nexport class Store extends PersistableStore {\n}\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { irand } from \"./rand.js\";\nexport const makeId = (pairs, digits, delim) => {\n pairs = pairs || 2;\n digits = digits || 2;\n delim = delim || '-';\n const min = Math.pow(10, digits - 1);\n const range = Math.pow(10, digits) - min;\n const result = [];\n for (let i = 0; i < pairs; i++) {\n result.push(`${irand(range - min) + min}`);\n }\n return result.join(delim);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Arc } from './core/Arc.js';\nimport { Host } from './core/Host.js';\nimport { Store } from './core/Store.js';\nimport { EventEmitter } from './core/EventEmitter.js';\nimport { logFactory } from './utils/log.js';\nimport { makeId } from './utils/id.js';\nconst log = logFactory(logFactory.flags.runtime, 'runtime', '#873600');\nconst particleFactoryCache = {};\nconst storeFactories = {};\nconst { keys } = Object;\nexport class Runtime extends EventEmitter {\n log;\n uid; // user id\n nid; // network id\n arcs;\n stores;\n peers;\n shares;\n endpoint;\n network;\n surfaces;\n persistor;\n prettyUid;\n static securityLockdown;\n static particleIndustry;\n static particleOptions;\n constructor(uid) {\n uid = uid || 'user';\n super();\n this.arcs = {};\n this.surfaces = {};\n this.stores = {};\n this.peers = new Set();\n this.shares = new Set();\n this.setUid(uid);\n this.log = logFactory(logFactory.flags.runtime, `runtime:[${this.prettyUid}]`, '#873600');\n //Runtime.securityLockdown?.(Runtime.particleOptions);\n }\n setUid(uid) {\n this.uid = uid;\n this.nid = `${uid}:${makeId(1, 2)}`;\n this.prettyUid = uid.substring(0, uid.indexOf('@') + 1) || uid;\n }\n async bootstrapArc(name, meta, surface, service) {\n // make an arc on `surface`\n const arc = new Arc(name, meta, surface);\n // install service handler\n arc.hostService = this.serviceFactory(service);\n // add `arc` to runtime\n await this.addArc(arc);\n // fin\n return arc;\n }\n serviceFactory(service) {\n return async (host, request) => service.handle(this, host, request);\n }\n // TODO(sjmiles): duplication vis a vis `installParticle`\n // used by? ... [ParticleCook.js]\n async bootstrapParticle(arc, id, meta) {\n // make a host\n const host = new Host(id);\n // make a particle\n await this.marshalParticle(host, meta);\n // add `host` to `arc`\n await arc.addHost(host);\n // report\n log('bootstrapped particle', id);\n //log(host);\n return host;\n }\n // no-op surface mapping\n addSurface(id, surface) {\n this.surfaces[id] = surface;\n }\n getSurface(id) {\n return this.surfaces[id];\n }\n // map arcs by arc.id\n addArc(arc) {\n const { id } = arc;\n if (id && !this.arcs[id]) {\n return this.arcs[id] = arc;\n }\n throw `arc has no id, or id \"${id}\" is already in use`;\n }\n removeArc(arc) {\n const { id } = arc;\n if (!id || !this.arcs[id]) {\n throw !id ? `arc has no id` : `id \"${id}\" is not in use`;\n }\n delete this.arcs[id];\n }\n // create a particle inside of host\n async marshalParticle(host, particleMeta) {\n const particle = await this.createParticle(host, particleMeta.kind);\n return host.installParticle(particle, particleMeta);\n }\n // create a host, install a particle, add host to arc\n // TODO(sjmiles): duplication vis a vis `bootstrapParticle`\n // used by? ... [ArcsWorker.js]\n async installParticle(arc, particleMeta, name) {\n this.log('installParticle', name, particleMeta, arc.id);\n // provide a default name\n name = name || makeId();\n // deduplicate name\n if (arc.hosts[name]) {\n let n = 1;\n for (; (arc.hosts[`${name}-${n}`]); n++)\n ;\n name = `${name}-${n}`;\n }\n // build the structure\n const host = new Host(name);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n }\n // TODO(sjmiles): third version to rule them all; bring your own host\n async addParticle(arc, host, particleMeta, name) {\n this.log('addParticle', arc.id, name, particleMeta, arc.id);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n // this.log('addParticle', name, particleMeta, arc.id);\n // // provide a default name\n // name = name || makeId();\n // // deduplicate name\n // if (arc.hosts[name]) {\n // let n = 1;\n // for (; (arc.hosts[`${name}-${n}`]); n++);\n // name = `${name}-${n}`;\n // }\n // // build the structure\n // const host = new Host(name);\n // await this.marshalParticle(host, particleMeta);\n // await arc.addHost(host);\n // return host;\n }\n idFromName(name, list) {\n // provide a default name\n let id = name || makeId();\n // deduplicate name\n if (list[id]) {\n let n = 1;\n for (; (list[`${id}-${n}`]); n++)\n ;\n id = `${id}-${n}`;\n }\n // return unique id\n return id;\n }\n // map a store by a Runtime-specific storeId\n // Stores have no intrinsic id\n addStore(storeId, store) {\n // if the store needs to discuss things with Runtime\n // TODO(sjmiles): this is likely unsafe for re-entry\n if (store.marshal) {\n store.marshal(this);\n }\n // bind to persist/restore functions\n store.persist = async () => this.persistStore(storeId, store);\n store.restore = async () => this.restoreStore(storeId, store);\n // override the Store's own persistor to use the runtime persistor\n // TODO(sjmiles): why?\n // if (store.persistor) {\n // store.persistor.persist = store => this.persistor?.persist(storeId, store);\n // }\n // bind this.storeChanged to store.change (and name the binding)\n const name = `${this.nid}:${storeId}-changed`;\n const onChange = this.storeChanged.bind(this, storeId);\n store.listen('change', onChange, name);\n // map the store\n this.stores[storeId] = store;\n // evaluate for sharing\n this.maybeShareStore(storeId);\n // notify listeners that a thing happened\n // TODO(sjmiles): makes no sense without id\n //this.fire('store-added', store);\n }\n async persistStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`persistStore \"${storeId}\"`);\n return this.persistor?.persist?.(storeId, store.data);\n }\n }\n async restoreStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`restoreStore \"${storeId}\"`);\n return this.persistor?.restore?.(storeId);\n }\n }\n storeChanged(storeId, store) {\n this.log('storeChanged', storeId);\n this.network?.invalidatePeers(storeId);\n this.onStoreChange(storeId, store);\n this.fire('store-changed', { storeId, store });\n }\n // TODO(sjmiles): evacipate this method\n onStoreChange(storeId, store) {\n // override for bespoke response\n }\n do(storeId, task) {\n task(this.stores[storeId]);\n }\n removeStore(storeId) {\n this.do(storeId, store => {\n store?.unlisten('change', `${this.nid}:${storeId}-changed`);\n });\n delete this.stores[storeId];\n }\n maybeShareStore(storeId) {\n this.do(storeId, store => {\n if (store?.is('shared')) {\n this.shareStore(storeId);\n }\n });\n }\n addPeer(peerId) {\n this.peers.add(peerId);\n [...this.shares].forEach(storeId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n shareStore(storeId) {\n this.shares.add(storeId);\n [...this.peers].forEach(peerId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n maybeShareStoreWithPeer(storeId, peerId) {\n this.do(storeId, store => {\n const nid = this.uid.replace(/\\./g, '_');\n if (!store.is('private') || (peerId.startsWith(nid))) {\n this.shareStoreWithPeer(storeId, peerId);\n }\n });\n }\n shareStoreWithPeer(storeId, peerId) {\n this.network?.shareStore(storeId, peerId);\n }\n async createParticle(host, kind) {\n try {\n const factory = await this.marshalParticleFactory(kind);\n return factory?.(host);\n }\n catch (x) {\n log.error(`createParticle(${kind}):`, x);\n }\n }\n async marshalParticleFactory(kind) {\n return particleFactoryCache[kind] ?? this.lateBindParticle(kind);\n }\n lateBindParticle(kind, code) {\n const { particleOptions, particleIndustry, registerFactoryPromise } = Runtime;\n if (!particleIndustry) {\n throw `no ParticleIndustry to create '${kind}'`;\n }\n else {\n const factoryPromise = particleIndustry(kind, { ...particleOptions, code });\n registerFactoryPromise(kind, factoryPromise);\n return factoryPromise;\n }\n }\n static registerFactoryPromise(kind, factoryPromise) {\n return particleFactoryCache[kind] = factoryPromise;\n }\n requireStore(meta) {\n let store = this.stores[meta.name];\n if (!store) {\n store = this.createStore(meta);\n this.addStore(meta.name, store);\n }\n return store;\n }\n createStore(meta) {\n const key = keys(storeFactories).find(tag => meta.tags?.includes?.(tag));\n const storeClass = storeFactories[String(key)] || Store;\n return new storeClass(meta);\n }\n static registerStoreClass(tag, storeClass) {\n storeFactories[tag] = storeClass;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'RecipeParser', 'violet');\nconst { entries, create } = Object;\nexport class Parser {\n stores;\n particles;\n slots;\n meta;\n constructor(recipe) {\n this.stores = [];\n this.particles = [];\n this.slots = [];\n this.meta = create(null);\n if (recipe) {\n this.parse(recipe);\n }\n }\n parse(recipe) {\n // `normalize` converts shorthand to longhand before parsing\n const normalized = this.normalize(recipe);\n this.parseSlotSpec(normalized, 'root', '');\n return this;\n }\n normalize(recipe) {\n if (typeof recipe !== 'object') {\n throw Error('recipe must be an Object');\n }\n // TODO(sjmiles): would be great if `normalize` normalized all the things\n return recipe;\n }\n parseSlotSpec(spec, slotName, parentName) {\n // process entries\n for (const key in spec) {\n switch (key) {\n case '$meta':\n // value is a dictionary\n this.meta = { ...this.meta, ...spec.$meta };\n break;\n case '$stores':\n // value is a StoreSpec\n this.parseStoresNode(spec.$stores);\n break;\n default: {\n // value is a ParticleSpec\n const container = parentName ? `${parentName}#${slotName}` : slotName;\n this.parseParticleSpec(container, key, spec[key]);\n break;\n }\n }\n }\n }\n parseStoresNode(stores) {\n for (const key in stores) {\n this.parseStoreSpec(key, stores[key]);\n }\n }\n parseStoreSpec(name, spec) {\n if (this.stores.find(s => s.name === name)) {\n log('duplicate store name');\n return;\n }\n const meta = {\n name,\n type: spec.$type,\n tags: spec.$tags,\n value: spec.$value\n };\n this.stores.push(meta);\n }\n parseParticleSpec(container, id, spec) {\n if (!spec.$kind) {\n log.warn(`parseParticleSpec: malformed spec has no \"kind\":`, spec);\n throw Error();\n }\n if (this.particles.find(s => s.id === id)) {\n log('duplicate particle name', id, spec);\n return;\n }\n this.particles.push({ id, container, spec });\n if (spec.$slots) {\n this.parseSlotsNode(spec.$slots, id);\n }\n }\n parseSlotsNode(slots, parent) {\n entries(slots).forEach(([key, spec]) => this.parseSlotSpec(spec, key, parent));\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport function matches(candidateMeta, targetMeta) {\n for (const property in targetMeta) {\n if (candidateMeta[property] !== targetMeta[property]) {\n return false;\n }\n }\n return true;\n}\n;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { matches } from '../utils/matching.js';\nconst log = logFactory(logFactory.flags.recipe, 'StoreCook', '#99bb15');\nconst { values } = Object;\nconst mapStore = (runtime, { name, type }) => {\n return findStores(runtime, { name, type })?.[0];\n};\nconst findStores = (runtime, criteria) => {\n return values(runtime.stores).filter(store => storeMatches(store, criteria));\n};\nconst storeMatches = (store, criteria) => {\n // TODO(b/244191110): Type matching API to be wired here.\n const { type, ...other } = criteria;\n if (typeMatches(type, store?.meta.type)) {\n // generic object comparison\n return matches(store?.meta, other);\n }\n};\nconst typeMatches = (typeA, typeB) => {\n const baseTypes = ['pojo', 'json'];\n return (typeA === typeB)\n || baseTypes.includes(typeA?.toLowerCase())\n || baseTypes.includes(typeB?.toLowerCase());\n};\nexport class StoreCook {\n static async execute(runtime, arc, stores) {\n return this.forEachStore(this.realizeStore, runtime, arc, stores);\n }\n static async evacipate(runtime, arc, stores) {\n return this.forEachStore(this.derealizeStore, runtime, arc, stores);\n }\n static async forEachStore(task, runtime, arc, stores) {\n return Promise.all(stores.map(store => task.call(this, runtime, arc, store)));\n }\n static async realizeStore(runtime, arc, rawMeta) {\n // potential initialization value\n let value;\n // build a StoreMeta out of parts\n const meta = this.constructMeta(runtime, arc, rawMeta);\n // do we already own this Store?\n let store = mapStore(runtime, meta);\n if (store) {\n // use a Store\n log(`realizeStore: mapping \"${rawMeta.name}\" to \"${store.meta.name}\"`);\n }\n else {\n log(`realizeStore: creating \"${meta.name}\"`);\n // create a Store\n store = StoreCook.createStore(runtime, meta);\n // default initial value comes from meta\n value = meta?.value;\n // persisted value may override default\n if (store.shouldPersist()) {\n const cached = await store.restore();\n value = (cached == null) ? value : cached;\n }\n }\n // we have a store for the Arc now\n arc.addStore(meta.name, store);\n // it may need a starting value\n if (value !== undefined) {\n log(`setting data to:`, value);\n store.data = value;\n }\n }\n static createStore(runtime, meta) {\n // we need to create this Store\n const store = runtime.createStore(meta);\n runtime.addStore(meta.name, store);\n return store;\n }\n static async derealizeStore(runtime, arc, meta) {\n log(`derealizeStore: derealizing \"${meta.name}\"`);\n runtime.removeStore(meta.name);\n arc.removeStore(meta.name);\n }\n static constructMeta(runtime, arc, rawMeta) {\n const meta = {\n ...rawMeta,\n arcid: arc.id,\n uid: runtime.uid,\n };\n return {\n ...meta,\n owner: meta.uid,\n shareid: `${meta.name}:${meta.arcid}:${meta.uid}`\n };\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'ParticleCook', '#5fa530');\nexport class ParticleCook {\n static async execute(runtime, arc, particles) {\n // serial\n for (const particle of particles) {\n await this.realizeParticle(runtime, arc, particle);\n }\n // parallel\n //return Promise.all(particles.map(particle => this.realizeParticle(runtime, arc, particle)));\n }\n static async realizeParticle(runtime, arc, node) {\n log('realizedParticle:', node.id);\n // convert spec to metadata\n const meta = this.specToMeta(node.spec);\n meta.container ||= node.container;\n // make a (hosted) particle\n return runtime.bootstrapParticle(arc, node.id, meta);\n }\n static specToMeta(spec) {\n if (spec.$bindings) {\n console.warn(`Particle '${spec.$kind}' spec contains deprecated $bindings property (${JSON.stringify(spec.$bindings)})`);\n }\n // TODO(sjmiles): impedance mismatch here is likely to cause problems\n const { $kind: kind, $container: container, $staticInputs: staticInputs } = spec;\n const inputs = this.formatBindings(spec.$inputs);\n const outputs = this.formatBindings(spec.$outputs);\n return { kind, staticInputs, inputs, outputs, container };\n }\n static formatBindings(bindings) {\n return bindings?.map?.(binding => typeof binding === 'string' ? { [binding]: binding } : binding);\n }\n static async evacipate(runtime, arc, particles) {\n return Promise.all(particles.map(particle => this.derealizeParticle(runtime, arc, particle)));\n }\n static async derealizeParticle(runtime, arc, node) {\n arc.removeHost(node.id);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { Parser } from './RecipeParser.js';\nimport { StoreCook } from './StoreCook.js';\nimport { ParticleCook } from './ParticleCook.js';\nconst log = logFactory(logFactory.flags.recipe, 'Chef', '#087f23');\nexport class Chef {\n static async execute(recipe, runtime, arc) {\n if (arc instanceof Promise) {\n log.error('`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.');\n return;\n }\n //log.groupCollapsed('executing recipe...', recipe.$meta);\n log('|-->...| executing recipe: ', recipe.$meta ?? '');\n const plan = new Parser(recipe);\n // `store` preparation\n await StoreCook.execute(runtime, arc, plan.stores);\n // `particle` preparation\n await ParticleCook.execute(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): what do we use this for?\n arc.meta = { ...arc.meta, ...plan.meta };\n log('|...-->| recipe complete: ', recipe.$meta ?? '');\n //log.groupEnd();\n }\n static async evacipate(recipe, runtime, arc) {\n //log.groupCollapsed('evacipating recipe...', recipe.$meta);\n log('|-->...| evacipating recipe: ', recipe.$meta);\n // TODO(sjmiles): this is work we already did\n const plan = new Parser(recipe);\n // `store` work\n // TODO(sjmiles): not sure what stores are unique to this plan\n await StoreCook.evacipate(runtime, arc, plan.stores);\n // `particle` work\n await ParticleCook.evacipate(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): doh\n //arc.meta = {...arc.meta, ...plan.meta};\n log('|...-->| recipe evacipated: ', recipe.$meta);\n //log.groupEnd();\n }\n static async executeAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.execute(recipe, runtime, arc);\n }\n }\n static async evacipateAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.evacipate(recipe, runtime, arc);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Paths } from '../utils/paths.js';\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.code, 'code', 'gold', '#333');\nconst defaultParticleBasePath = '$arcs/core/Particle.js';\n// acquire particle code\n// `kind` describes the particle\n// `options.code` may simply provide code directly\nexport const requireParticleImplCode = async (kind, options) => {\n const code = options?.code || await fetchParticleCode(kind);\n // TODO(sjmiles): brittle content processing, needs to be documented\n return code.slice(code.indexOf('({'));\n};\nexport const fetchParticleCode = async (kind) => {\n if (kind) {\n return await maybeFetchParticleCode(kind);\n }\n log.error(`fetchParticleCode: empty 'kind'`);\n};\nexport const maybeFetchParticleCode = async (kind) => {\n const path = pathForKind(kind);\n try {\n const response = await fetch(path);\n if (response.ok) {\n return await response.text();\n }\n else {\n throw '';\n }\n }\n catch (x) {\n log.error(`could not locate implementation for particle \"${kind}\" [${path}]`);\n }\n};\nexport const pathForKind = (kind) => {\n if (kind) {\n if (!'$./'.includes(kind[0]) && !kind.includes('://')) {\n kind = `$library/${kind}`;\n }\n if (!kind?.split('/').pop().includes('.')) {\n kind = `${kind}.js`;\n }\n return Paths.resolve(kind);\n }\n return '404';\n};\n// acquire Particle.js\nexport const requireParticleBaseCode = async (sourcePath) => {\n if (!requireParticleBaseCode.source) {\n const path = Paths.resolve(sourcePath || defaultParticleBasePath);\n log('particle base code path: ', path);\n const response = await fetch(path);\n const moduleText = await response.text() + \"\\n//# sourceURL=\" + path + \"\\n\";\n requireParticleBaseCode.source = moduleText.replace(/export /g, '');\n }\n return requireParticleBaseCode.source;\n};\nrequireParticleBaseCode.source = null;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const PathMapper = class {\n map;\n constructor(root) {\n this.map = {};\n this.setRoot(root);\n }\n add(mappings) {\n Object.assign(this.map, mappings || {});\n }\n resolve(path) {\n let last;\n do {\n path = this._resolve(last = path);\n } while (last !== path);\n return path;\n }\n _resolve(path) {\n const bits = path.split('/');\n const top = bits.shift();\n const prefix = this.map[top] || top;\n return [prefix, ...bits].join('/');\n }\n setRoot(root) {\n if (root.length && root[root.length - 1] === '/') {\n root = root.slice(0, -1);\n }\n this.add({\n '$root': root,\n '$arcs': root\n });\n }\n getAbsoluteHereUrl(meta, depth) {\n // you are here\n const localRelative = meta.url.split('/').slice(0, -(depth ?? 1)).join('/');\n if (!globalThis?.document) {\n return localRelative;\n }\n else {\n // document root is here\n let base = document.URL;\n // if document URL has a filename, remove it\n if (base[base.length - 1] !== '/') {\n base = `${base.split('/').slice(0, -1).join('/')}/`;\n }\n // create absoute path to here (aka 'local')\n let localAbsolute = new URL(localRelative, base).href;\n // no trailing slash!\n if (localAbsolute[localAbsolute.length - 1] === '/') {\n localAbsolute = localAbsolute.slice(0, -1);\n }\n return localAbsolute;\n }\n }\n};\nconst root = import.meta.url.split('/').slice(0, -3).join('/');\nexport const Paths = globalThis['Paths'] = new PathMapper(root);\nPaths.add(globalThis.config?.paths);\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport * from './date.js';\nexport * from './id.js';\nexport * from './log.js';\nexport * from './matching.js';\nexport * from './object.js';\nexport * from './paths.js';\nexport * from './rand.js';\nexport * from './task.js';\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const computeAgeString = (date, now) => {\n let deltaTime = Math.round((now - date) / 1000);\n if (isNaN(deltaTime)) {\n return `\u2022`;\n }\n let plural = '';\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} second${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} minute${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 24) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} hour${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 24);\n if (deltaTime < 30) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} day${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 30);\n if (deltaTime < 12) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} month${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 12);\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} year${plural} ago`;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/**\n * Perform `action` if `delay` ms have elapsed since last debounce call for `key`.\n *\n * ```\n * // invoke 'task' one second after last time this line executed\n * this.debounceTask = debounce(this.debounceTask, task, 1000);\n * ```\n */\nexport const debounce = (key, action, delay) => {\n if (key) {\n clearTimeout(key);\n }\n if (action && delay) {\n return setTimeout(action, delay);\n }\n};\nexport const async = task => {\n return async (...args) => {\n await Promise.resolve();\n task(...args);\n };\n};\nexport const asyncTask = (task, delayMs) => {\n setTimeout(task, delayMs ?? 0);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n\nexport * from '../js/Runtime.js';\nexport * from '../js/core/EventEmitter.js';\nexport * from '../js/core/Store.js';\nexport * from '../js/core/Arc.js';\nexport * from '../js/core/Host.js';\nexport * from '../js/core/Decorator.js';\nexport * from '../js/recipe/Chef.js';\nexport * from '../js/recipe/ParticleCook.js';\nexport * from '../js/recipe/StoreCook.js';\nexport * from '../js/recipe/RecipeParser.js';\nexport * as code from '../js/isolation/code.js';\n\nimport * as utils from '../js/utils/utils.js';\nconst {logFactory, Paths} = utils;\nexport {logFactory, Paths, utils};\n\nconst root = import.meta.url.split('/').slice(0, -1).join('/');\nPaths.setRoot(root);\n"], - "mappings": ";;;;;;;;;;;;AAQO,IAAM,eAAN,MAAmB;AAAA,EAEtB,YAAY,CAAC;AAAA,EACb,kBAAkB,WAAW;AACzB,WAAO,KAAK,UAAU,eAAe,KAAK,UAAU,aAAa,CAAC;AAAA,EACtE;AAAA,EACA,KAAK,cAAc,MAAM;AACrB,UAAM,YAAY,KAAK,kBAAkB,SAAS;AAClD,QAAI,WAAW,SAAS;AACpB,gBAAU,QAAQ,cAAY,SAAS,GAAG,IAAI,CAAC;AAAA,IACnD;AAAA,EACJ;AAAA,EACA,OAAO,WAAW,UAAU,cAAc;AACtC,UAAM,YAAY,KAAK,kBAAkB,SAAS;AAClD,cAAU,KAAK,QAAQ;AACvB,aAAS,QAAQ,gBAAgB;AACjC,WAAO;AAAA,EACX;AAAA,EACA,SAAS,WAAW,UAAU;AAC1B,UAAM,OAAO,KAAK,kBAAkB,SAAS;AAC7C,UAAM,QAAS,OAAO,aAAa,WAAY,KAAK,UAAU,OAAK,EAAE,UAAU,QAAQ,IAAI,KAAK,QAAQ,QAAQ;AAChH,QAAI,SAAS,GAAG;AACZ,WAAK,OAAO,OAAO,CAAC;AAAA,IACxB,OACK;AACD,cAAQ,KAAK,2BAA2B,SAAS;AAAA,IACrD;AAAA,EACJ;AACJ;;;AC5BO,IAAM,WAAW,CAAC,OAAO,SAAS,kBAAkB,YAAY,KAAK;AACrE,IAAM,WAAW,CAAC,QAAQ,OAAO;;;ACAxC,IAAM,EAAE,YAAY,IAAI;AACxB,IAAM,cAAc,CAAC,QAAQ,UAAU,IAAI,OAAO,OAAO,UAAU;AAC/D,MAAI,OAAO,WAAW,UAAU;AAC5B,aAAS,WAAW,MAAM;AA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AACb,SAAO,GAAG,iBAAiB;AAC/B;;;AC/BO,IAAM,WAAW,CAACC,MAAK,QAAQ,UAAU;AAC5C,MAAIA,MAAK;AACL,iBAAaA,IAAG;AAAA,EACpB;AACA,MAAI,UAAU,OAAO;AACjB,WAAO,WAAW,QAAQ,KAAK;AAAA,EACnC;AACJ;AACO,IAAM,QAAQ,UAAQ;AACzB,SAAO,UAAU,SAAS;AACtB,UAAM,QAAQ,QAAQ;AACtB,SAAK,GAAG,IAAI;AAAA,EAChB;AACJ;AACO,IAAM,YAAY,CAAC,MAAM,YAAY;AACxC,aAAW,MAAM,WAAW,CAAC;AACjC;;;ACTA,IAAM,EAAC,YAAAC,aAAY,OAAAC,OAAK,IAAI;AAG5B,IAAMC,QAAO,YAAY,IAAI,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG;AAC7DC,OAAM,QAAQD,KAAI;", + "sourcesContent": ["/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport class EventEmitter {\n // map of event name to listener array\n listeners = {};\n getEventListeners(eventName) {\n return this.listeners[eventName] || (this.listeners[eventName] = []);\n }\n fire(eventName, ...args) {\n const listeners = this.getEventListeners(eventName);\n if (listeners?.forEach) {\n listeners.forEach(listener => listener(...args));\n }\n }\n listen(eventName, listener, listenerName) {\n const listeners = this.getEventListeners(eventName);\n listeners.push(listener);\n listener._name = listenerName || '(unnamed listener)';\n return listener;\n }\n unlisten(eventName, listener) {\n const list = this.getEventListeners(eventName);\n const index = (typeof listener === 'string') ? list.findIndex(l => l._name === listener) : list.indexOf(listener);\n if (index >= 0) {\n list.splice(index, 1);\n }\n else {\n console.warn('failed to unlisten from', eventName);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const logKinds = ['log', 'group', 'groupCollapsed', 'groupEnd', 'dir'];\nexport const errKinds = ['warn', 'error'];\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logKinds, errKinds } from './types.js';\nconst { fromEntries } = Object;\nconst _logFactory = (enable, preamble, bg, color, kind = 'log') => {\n if (typeof enable === 'string') {\n enable = logFactory.flags[enable];\n }\n if (!enable) {\n return () => { };\n }\n if (kind === 'dir') {\n return console.dir.bind(console);\n }\n const style = `background: ${bg || 'gray'}; color: ${color || 'white'}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;\n return console[kind].bind(console, `%c${preamble}`, style);\n};\nexport const logFactory = (enable, preamble, bg = '', color = '') => {\n const debugLoggers = fromEntries(logKinds.map(kind => [kind, _logFactory(enable, preamble, bg, color, kind)]));\n const errorLoggers = fromEntries(errKinds.map(kind => [kind, _logFactory(true, preamble, bg, color, kind)]));\n const loggers = { ...debugLoggers, ...errorLoggers };\n // Inject `log` as default, keeping all loggers available to be invoked by name.\n const log = loggers.log;\n Object.assign(log, loggers);\n return log;\n};\nlogFactory.flags = globalThis.config?.logFlags || {};\n", "/**\n * @license\n * Copyright (c) 2022 Google LLC All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\nimport { EventEmitter } from './EventEmitter.js';\nimport { logFactory } from '../utils/log.js';\nconst customLogFactory = (id) => logFactory(logFactory.flags.arc, `Arc (${id})`, 'slateblue');\nconst { assign, create } = Object;\nconst entries = (o) => Object.entries(o ?? Object);\nconst keys = (o) => Object.keys(o ?? Object);\nconst values = (o) => Object.values(o ?? Object);\nconst nob = () => create(null);\nexport class Arc extends EventEmitter {\n log;\n id;\n meta;\n stores;\n hosts;\n surface;\n composer;\n hostService;\n constructor(id, meta, surface) {\n super();\n this.id = id;\n this.meta = meta;\n this.surface = surface;\n this.hosts = nob();\n this.stores = nob();\n this.log = customLogFactory(id);\n }\n async addHost(host, surface) {\n // to support hosts we need a composer\n await this.ensureComposer();\n // bookkeep\n this.hosts[host.id] = host;\n host.arc = this;\n // TODO(sjmiles): support per host surfacing?\n //await host.bindToSurface(surface ?? this.surface);\n // begin work\n this.updateHost(host);\n return host;\n }\n async ensureComposer() {\n if (!this.composer && this.surface) {\n // create composer\n this.composer = await this.surface.createComposer('root');\n // pipeline for events from composer to this.onevent\n // TODO(sjmiles): use 'bind' to avoid a closure and improve the stack trace\n this.composer.onevent = this.onevent.bind(this);\n }\n }\n rerender() {\n values(this.hosts).forEach(h => h.rerender());\n }\n removeHost(id) {\n this.hosts[id]?.detach();\n delete this.hosts[id];\n }\n addStore(storeId, store) {\n if (store && !this.stores[storeId]) {\n this.stores[storeId] = store;\n store.listen('change', () => this.storeChanged(storeId, store), this.id);\n }\n }\n removeStore(storeId) {\n const store = this.stores[storeId];\n if (store) {\n store.unlisten('change', this.id);\n }\n delete this.stores[storeId];\n }\n // TODO(sjmiles): 2nd param is used in overrides, make explicit\n storeChanged(storeId, store) {\n this.log(`storeChanged: \"${storeId}\"`);\n const isBound = inputs => inputs && inputs.some(input => input && (values(input)[0] == storeId || keys(input)[0] == storeId));\n values(this.hosts).forEach(host => {\n const inputs = host.meta?.inputs;\n if (inputs === '*' || isBound(inputs)) {\n this.log(`host \"${host.id}\" has interest in \"${storeId}\"`);\n // TODO(sjmiles): we only have to update inputs for storeId, we lose efficiency here\n this.updateHost(host);\n }\n });\n this.fire('store-changed', storeId);\n }\n updateParticleMeta(hostId, meta) {\n const host = this.hosts[hostId];\n host.meta = meta;\n this.updateHost(host);\n }\n updateHost(host) {\n host.inputs = this.computeInputs(host);\n }\n // TODO(sjmiles): debounce? (update is sync-debounced already)\n // complement to `assignOutputs`\n computeInputs(host) {\n const inputs = nob();\n const inputBindings = host.meta?.inputs;\n if (inputBindings === '*') {\n // TODO(sjmiles): we could make the contract that the bindAll inputs are\n // names (or names + meta) only. The Particle could look up values via\n // service (to reduce throughput requirements)\n entries(this.stores).forEach(([name, store]) => inputs[name] = store.pojo);\n }\n else {\n const staticInputs = host.meta?.staticInputs;\n assign(inputs, staticInputs);\n if (inputBindings) {\n inputBindings.forEach(input => input && this.computeInput(entries(input)[0], inputs));\n this.log(`computeInputs(${host.id}) =`, inputs);\n }\n }\n return inputs;\n }\n computeInput([name, binding], inputs) {\n const storeName = binding || name;\n const store = this.stores[storeName];\n if (store) {\n inputs[name] = store.pojo;\n }\n else {\n // TODO(sjmiles): is this ok or not?\n //this.log.warn(`computeInput: \"${storeName}\" (bound to \"${name}\") not found`);\n }\n }\n // complement to `computeInputs`\n assignOutputs({ id, meta }, outputs) {\n const names = keys(outputs);\n if (meta?.outputs && names.length) {\n names.forEach(name => this.assignOutput(name, outputs[name], meta.outputs));\n this.log(`[end][${id}] assignOutputs:`, outputs);\n }\n }\n assignOutput(name, output, outputs) {\n if (output !== undefined) {\n const binding = this.findOutputByName(outputs, name) || name;\n const store = this.stores[binding];\n if (!store) {\n if (outputs?.[name]) {\n this.log.warn(`assignOutputs: no \"${binding}\" store for output \"${name}\"`);\n }\n }\n else {\n // Note: users can mess up output data in any way they see fit, so we should\n // probably invent `outputCleansing`.\n this.log(`assignOutputs: \"${name}\" is dirty, updating Store \"${binding}\"`, output);\n store.data = output;\n }\n }\n }\n findOutputByName(outputs, name) {\n const output = outputs?.find(output => keys(output || 0)[0] === name);\n if (output) {\n return values(output)[0];\n }\n }\n async render(packet) {\n if (this.composer) {\n this.composer.render({ ...packet, arcid: this.id });\n }\n else {\n //this.log.low('render called, but composer is null', packet);\n }\n }\n onevent(pid, eventlet) {\n const host = this.hosts[pid];\n if (host) {\n host.handleEvent(eventlet);\n }\n }\n async service(host, request) {\n let result = await this.surface?.service(request);\n if (result === undefined) {\n result = this.hostService?.(host, request);\n }\n return result;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/*\n * update the fields of `obj` with the fields of `data`,\n * perturbing `obj` as little as possible (since it might be a magic proxy thing\n * like an Automerge document)\n */\nexport const shallowUpdate = (obj, data) => {\n let result = data;\n if (!data) {\n //\n }\n else if (Array.isArray(data)) {\n if (!Array.isArray(obj)) {\n // TODO(sjmiles): eek, very perturbing to obj\n obj = [];\n }\n for (let i = 0; i < data.length; i++) {\n const value = data[i];\n if (obj[i] !== value) {\n obj[i] = value;\n }\n }\n const overage = obj.length - data.length;\n if (overage > 0) {\n obj.splice(data.length, overage);\n }\n }\n else if (typeof data === 'object') {\n result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n const seen = {};\n // for each key in input data ...\n Object.keys(data).forEach(key => {\n // copy that data into output\n result[key] = data[key];\n // remember the key\n seen[key] = true;\n });\n // for each key in the output data...\n Object.keys(result).forEach(key => {\n // if this key was not in the input, remove it\n if (!seen[key]) {\n delete result[key];\n }\n });\n }\n return result;\n};\nexport const shallowMerge = (obj, data) => {\n if (data == null) {\n return null;\n }\n if (typeof data === 'object') {\n const result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n Object.keys(data).forEach(key => result[key] = data[key]);\n return result;\n }\n return data;\n};\nexport function deepCopy(datum) {\n if (!datum) {\n return datum;\n }\n else if (Array.isArray(datum)) {\n // This is trivially type safe but tsc needs help\n return datum.map(element => deepCopy(element));\n }\n else if (typeof datum === 'object') {\n const clone = Object.create(null);\n Object.entries(datum).forEach(([key, value]) => {\n clone[key] = deepCopy(value);\n });\n return clone;\n }\n else {\n return datum;\n }\n}\nexport const deepEqual = (a, b) => {\n const type = typeof a;\n // must be same type to be equal\n if (type !== typeof b) {\n return false;\n }\n // we are `deep` because we recursively study object types\n if (type === 'object' && a && b) {\n const aProps = Object.getOwnPropertyNames(a);\n const bProps = Object.getOwnPropertyNames(b);\n // equal if same # of props, and no prop is not deepEqual\n return (aProps.length == bProps.length) && !aProps.some(name => !deepEqual(a[name], b[name]));\n }\n // finally, perform simple comparison\n return (a === b);\n};\nexport const deepUndefinedToNull = (obj) => {\n if (obj === undefined) {\n return null;\n }\n if (obj && (typeof obj === 'object')) {\n // we are `deep` because we recursively study object types\n const props = Object.getOwnPropertyNames(obj);\n props.forEach(name => {\n const prop = obj[name];\n if (prop === undefined) {\n delete obj[name];\n //obj[name] = null;\n }\n else {\n deepUndefinedToNull(prop);\n }\n });\n }\n return obj;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nconst { floor, pow, random } = Math;\n// random n-digit number\nexport const key = (digits) => floor((1 + random() * 9) * pow(10, digits - 1));\n// random integer from [0..range)\nexport const irand = (range) => floor(random() * range);\n// random element from array\nexport const arand = (array) => array[irand(array.length)];\n// test if event has occured, where `probability` is between [0..1]\nexport const prob = (probability) => Boolean(random() < probability);\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepCopy } from '../utils/object.js';\nconst log = logFactory(logFactory.flags.decorator, 'Decorator', 'plum');\nconst { values, entries } = Object;\nconst opaqueData = {};\nexport const Decorator = {\n setOpaqueData(name, data) {\n opaqueData[name] = data; //deepCopy(data);\n return name;\n },\n getOpaqueData(name) {\n return opaqueData[name];\n },\n maybeDecorateModel(model, particle) {\n if (model && !Array.isArray(model)) {\n // for each item in model, regardless of key\n values(model).forEach((item) => {\n // is an object?\n if (item && (typeof item === 'object')) {\n // are there sub-models\n if (item['models']) {\n // the decorate this item\n log('applying decorator(s) to list:', item);\n this.maybeDecorateItem(item, particle);\n }\n else {\n // otherwise, check if there are sub-items to decorate\n if (model?.filter || model?.decorator || model?.collateBy) {\n log('scanning for lists in sub-model:', item);\n this.maybeDecorateModel(item, particle);\n }\n }\n }\n });\n }\n // possibly decorated model\n return model;\n },\n maybeDecorateItem(item, particle) {\n let models = (typeof item.models === 'string') ? this.getOpaqueData(item.models) : item.models;\n if (models) {\n // do a decorator\n models = maybeDecorate(models, item.decorator, particle);\n // do a filter\n models = maybeFilter(models, item.filter, particle.impl);\n // do a collator\n models = maybeCollateBy(models, item);\n // mutate items\n item.models = models;\n //console.log(JSON.stringify(models, null, ' '));\n }\n },\n};\nconst maybeDecorate = (models, decorator, particle) => {\n decorator = particle.impl[decorator] ?? decorator;\n const { inputs, state } = particle.internal;\n if (decorator) {\n // TODO(cromwellian): Could be expensive to do everything, store responsibility?\n const immutableInputs = Object.freeze(deepCopy(inputs));\n // we don't want the decorator to have access to mutable globals\n const immutableState = Object.freeze(deepCopy(state));\n // models become decorous\n models = models.map(model => {\n // use previously mutated data or initialize\n // TODO(cromwellian): I'd like to do Object.freeze() here, also somehow not mutate the models inplace\n // Possibly have setOpaqueData wrap the data so the privateData lives on the wrapper + internal immutable data\n model.privateData = model.privateData || {};\n // TODO(cromwellian): also could be done once during setOpaqueData() if we can track privateData differently\n const immutableModel = Object.freeze(deepCopy(model));\n const decorated = decorator(immutableModel, immutableInputs, immutableState);\n // set new privateData from returned\n model.privateData = decorated.privateData;\n return { ...decorated, ...model, };\n });\n // sort (possible that all values undefined)\n models.sort(sortByLc('sortKey'));\n log('decoration was performed');\n }\n //models.forEach(model => delete model.privateData);\n return models;\n};\nconst maybeFilter = (models, filter, impl) => {\n filter = impl[filter] ?? filter;\n if (filter && models) {\n // models become filtrated\n models = models.filter(filter);\n }\n return models;\n};\nconst maybeCollateBy = (models, item) => {\n // construct requested sub-lists\n entries(item).forEach(([name, collator]) => {\n // generate named collations for items of the form `[name]: {collateBy}`\n if (collator?.['collateBy']) {\n // group the models into buckets based on the model-field named by `collateBy`\n const collation = collate(models, collator['collateBy']);\n models = collationToRenderModels(collation, name, collator['$template']);\n }\n });\n return models;\n};\nconst sortByLc = key => (a, b) => sort(String(a[key]).toLowerCase(), String(b[key]).toLowerCase());\n//const sortBy = key => (a, b) => sort(a[key], b[key]);\nconst sort = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst collate = (models, collateBy) => {\n const collation = {};\n models.forEach(model => {\n const keyValue = model[collateBy];\n if (keyValue) {\n const category = collation[keyValue] || (collation[keyValue] = []);\n category.push(model);\n }\n });\n return collation;\n};\nconst collationToRenderModels = (collation, name, $template) => {\n return entries(collation).map(([key, models]) => ({\n key,\n [name]: { models, $template },\n single: !(models['length'] !== 1),\n ...models?.[0]\n }));\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepEqual, deepCopy } from '../utils/object.js';\nimport { arand } from '../utils/rand.js';\nimport { EventEmitter } from './EventEmitter.js';\nimport { Decorator } from './Decorator.js';\nconst { entries, keys } = Object;\nconst customLogFactory = (id) => logFactory(logFactory.flags.host, `Host (${id})`, arand(['#5a189a', '#51168b', '#48137b', '#6b2fa4', '#7b46ae', '#3f116c']));\n/**\n * Host owns metadata (e.g. `id`, `container`) that its Particle is not allowed to access.\n * Host knows how to talk, asynchronously, to its Particle (potentially using a bus).\n**/\n/* TODO(sjmiles):\nUpdate Cycle Documented Briefly\n1. when a Store changes it invokes it's listeners\n2. when an Arc hears a Store change, it updates Hosts bound to the Store\n3. Arc updates Host by creating an `inputs` object from Stores and metadata\n - ignores fact inputs are accumulated\n - ignores information about which Store has updated\n4. `inputs` object is assigned to `hosts.inputs` \uD83D\uDE43\n5. Host does an expensive `deepEqual` equality check. Turning on `host` logging should reveal `this.log('inputs are not interesting, skipping update');` if data is caught in this trap\n - we can use reference testing here if we are more careful\n about using immutable data\n6. the particle.inputs are assigned (but is really a *merge*)\n*/\nexport class Host extends EventEmitter {\n arc;\n id;\n lastOutput;\n lastPacket;\n lastRenderModel;\n log;\n meta;\n particle;\n constructor(id) {\n super();\n this.log = customLogFactory(id);\n this.id = id;\n }\n onevent(eventlet) {\n this.arc?.onevent(eventlet);\n this.fire('eventlet', eventlet);\n }\n // Particle and ParticleMeta are separate, host specifically integrates these on behalf of Particle\n installParticle(particle, meta) {\n if (this.particle) {\n this.detachParticle();\n }\n if (particle) {\n this.particle = particle;\n this.meta = meta || this.meta;\n }\n }\n get container() {\n return this.meta?.container || 'root';\n }\n detach() {\n this.detachParticle();\n this.arc = null;\n }\n detachParticle() {\n if (this.particle) {\n this.render({ $clear: true });\n this.particle = null;\n this.meta = null;\n }\n }\n async service(request) {\n if (request?.decorate) {\n return Decorator.maybeDecorateModel(request.model, this.particle);\n }\n return this.arc?.service(this, request);\n }\n output(outputModel, renderModel) {\n if (outputModel) {\n this.lastOutput = outputModel;\n this.arc?.assignOutputs(this, outputModel);\n this.fire('output', outputModel);\n }\n if (this.template) {\n Decorator.maybeDecorateModel(renderModel, this.particle);\n this.lastRenderModel = { ...renderModel };\n this.render(renderModel);\n }\n }\n rerender() {\n // does not re-render Frame/Slot content\n // you probably want Arc::rerender\n if (this.lastRenderModel) {\n this.render(this.lastRenderModel);\n }\n }\n render(model) {\n const { id, container, template } = this;\n const content = { model, template };\n const packet = { id, container, content };\n this.fire('render', packet);\n this.arc?.render(packet);\n this.lastPacket = packet;\n }\n set inputs(inputs) {\n if (this.particle && inputs) {\n const lastInputs = this.particle.internal.inputs;\n if (this.dirtyCheck(inputs, lastInputs, this.lastOutput)) {\n this.particle.inputs = deepCopy({ ...this.meta?.staticInputs, ...inputs });\n this.fire('inputs-changed');\n }\n else {\n this.log('inputs are uninteresting, skipping update');\n }\n }\n }\n dirtyCheck(inputs, lastInputs, lastOutput) {\n const dirtyBits = ([n, v]) => (lastOutput?.[n] && !deepEqual(lastOutput[n], v))\n || !deepEqual(lastInputs?.[n], v);\n return !lastInputs\n || entries(inputs).length !== this.lastInputsLength(lastInputs)\n || entries(inputs).some(dirtyBits);\n }\n lastInputsLength(lastInputs) {\n return keys(lastInputs).filter(key => !this.meta?.staticInputs?.[key] && key !== 'eventlet').length;\n }\n get config() {\n return this.particle?.config;\n }\n get template() {\n return this.config?.template;\n }\n invalidate() {\n this.particle?.invalidate();\n }\n handleEvent(eventlet) {\n return this.particle?.handleEvent(eventlet);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { EventEmitter } from './EventEmitter.js';\nconst { create, keys } = Object;\nconst { stringify, parse } = JSON;\nexport class DataStore extends EventEmitter {\n privateData;\n constructor() {\n super();\n }\n setPrivateData(data) {\n this.privateData = data;\n }\n set data(data) {\n this.setPrivateData(data);\n }\n get data() {\n return this.privateData;\n }\n toString() {\n return this.pretty;\n }\n get isObject() {\n return this.data && typeof this.data === 'object';\n }\n get pojo() {\n return this.data;\n }\n get json() {\n return stringify(this.data);\n }\n set json(json) {\n let value = null;\n try {\n value = parse(json);\n }\n catch (x) {\n //\n }\n this.data = value;\n }\n get pretty() {\n const sorted = {};\n const pojo = this.pojo;\n keys(pojo).sort().forEach(key => sorted[key] = pojo[key]);\n return stringify(sorted, null, ' ');\n }\n}\nclass ObservableStore extends DataStore {\n change(mutator) {\n mutator(this);\n this.doChange();\n }\n doChange() {\n this.fire('change', this);\n this.onChange(this);\n }\n onChange(store) {\n // override\n }\n set data(data) {\n this.change(self => self.setPrivateData(data));\n }\n // TODO(sjmiles): one of the compile/build/bundle tools\n // evacipates the inherited getter, so we clone it\n get data() {\n return this['privateData'];\n }\n set(key, value) {\n if (!this.data) {\n this.setPrivateData(create(null));\n }\n if (value !== undefined) {\n this.change(self => self.data[key] = value);\n }\n else {\n this.delete(key);\n }\n }\n delete(key) {\n this.change(doc => delete doc.data[key]);\n }\n}\nclass PersistableStore extends ObservableStore {\n meta;\n constructor(meta) {\n super();\n this.meta = { ...meta };\n }\n toString() {\n return `${JSON.stringify(this.meta, null, ' ')}, ${this.pretty}`;\n }\n get tags() {\n return this.meta.tags ?? (this.meta.tags = []);\n }\n is(...tags) {\n // true if every member of `tags` is also in `this.tags`\n return tags.every(tag => this.tags.includes(tag));\n }\n isCollection() {\n return this.meta.type?.[0] === '[';\n }\n shouldPersist() {\n return this.is('persisted') && !this.is('volatile');\n }\n async doChange() {\n // do not await\n this.persist();\n return super.doChange();\n }\n // TODO(sjmiles): as of now the persist/restore methods\n // are bound in Runtime:addStore\n async persist() {\n }\n async restore( /*value: any*/) {\n }\n // delete() {\n // this.persistor?.remove(this);\n // }\n save() {\n return this.json;\n }\n load(serial, defaultValue) {\n let value = defaultValue;\n try {\n if (serial) {\n value = parse(serial);\n }\n }\n catch (x) {\n //\n }\n if (value !== undefined) {\n this.data = value;\n }\n }\n}\nexport class Store extends PersistableStore {\n}\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { irand } from \"./rand.js\";\nexport const makeId = (pairs, digits, delim) => {\n pairs = pairs || 2;\n digits = digits || 2;\n delim = delim || '-';\n const min = Math.pow(10, digits - 1);\n const range = Math.pow(10, digits) - min;\n const result = [];\n for (let i = 0; i < pairs; i++) {\n result.push(`${irand(range - min) + min}`);\n }\n return result.join(delim);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Arc } from './core/Arc.js';\nimport { Host } from './core/Host.js';\nimport { Store } from './core/Store.js';\nimport { EventEmitter } from './core/EventEmitter.js';\nimport { logFactory } from './utils/log.js';\nimport { makeId } from './utils/id.js';\nconst log = logFactory(logFactory.flags.runtime, 'runtime', '#873600');\nconst particleFactoryCache = {};\nconst storeFactories = {};\nconst { keys } = Object;\nexport class Runtime extends EventEmitter {\n log;\n uid; // user id\n nid; // network id\n arcs;\n stores;\n peers;\n shares;\n endpoint;\n network;\n surfaces;\n persistor;\n prettyUid;\n static securityLockdown;\n static particleIndustry;\n static particleOptions;\n constructor(uid) {\n uid = uid || 'user';\n super();\n this.arcs = {};\n this.surfaces = {};\n this.stores = {};\n this.peers = new Set();\n this.shares = new Set();\n this.setUid(uid);\n this.log = logFactory(logFactory.flags.runtime, `runtime:[${this.prettyUid}]`, '#873600');\n //Runtime.securityLockdown?.(Runtime.particleOptions);\n }\n setUid(uid) {\n this.uid = uid;\n this.nid = `${uid}:${makeId(1, 2)}`;\n this.prettyUid = uid.substring(0, uid.indexOf('@') + 1) || uid;\n }\n async bootstrapArc(name, meta, surface, service) {\n // make an arc on `surface`\n const arc = new Arc(name, meta, surface);\n // install service handler\n arc.hostService = this.serviceFactory(service);\n // add `arc` to runtime\n await this.addArc(arc);\n // fin\n return arc;\n }\n serviceFactory(service) {\n return async (host, request) => service.handle(this, host, request);\n }\n // TODO(sjmiles): duplication vis a vis `installParticle`\n // used by? ... [ParticleCook.js]\n async bootstrapParticle(arc, id, meta) {\n // make a host\n const host = new Host(id);\n // make a particle\n await this.marshalParticle(host, meta);\n // add `host` to `arc`\n await arc.addHost(host);\n // report\n log('bootstrapped particle', id);\n //log(host);\n return host;\n }\n // no-op surface mapping\n addSurface(id, surface) {\n this.surfaces[id] = surface;\n }\n getSurface(id) {\n return this.surfaces[id];\n }\n // map arcs by arc.id\n addArc(arc) {\n const { id } = arc;\n if (id && !this.arcs[id]) {\n return this.arcs[id] = arc;\n }\n throw `arc has no id, or id \"${id}\" is already in use`;\n }\n removeArc(arc) {\n const { id } = arc;\n if (!id || !this.arcs[id]) {\n throw !id ? `arc has no id` : `id \"${id}\" is not in use`;\n }\n delete this.arcs[id];\n }\n // create a particle inside of host\n async marshalParticle(host, particleMeta) {\n const particle = await this.createParticle(host, particleMeta.kind);\n return host.installParticle(particle, particleMeta);\n }\n // create a host, install a particle, add host to arc\n // TODO(sjmiles): duplication vis a vis `bootstrapParticle`\n // used by? ... [ArcsWorker.js]\n async installParticle(arc, particleMeta, name) {\n this.log('installParticle', name, particleMeta, arc.id);\n // provide a default name\n name = name || makeId();\n // deduplicate name\n if (arc.hosts[name]) {\n let n = 1;\n for (; (arc.hosts[`${name}-${n}`]); n++)\n ;\n name = `${name}-${n}`;\n }\n // build the structure\n const host = new Host(name);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n }\n // TODO(sjmiles): third version to rule them all; bring your own host\n async addParticle(arc, host, particleMeta, name) {\n this.log('addParticle', arc.id, name, particleMeta, arc.id);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n // this.log('addParticle', name, particleMeta, arc.id);\n // // provide a default name\n // name = name || makeId();\n // // deduplicate name\n // if (arc.hosts[name]) {\n // let n = 1;\n // for (; (arc.hosts[`${name}-${n}`]); n++);\n // name = `${name}-${n}`;\n // }\n // // build the structure\n // const host = new Host(name);\n // await this.marshalParticle(host, particleMeta);\n // await arc.addHost(host);\n // return host;\n }\n idFromName(name, list) {\n // provide a default name\n let id = name || makeId();\n // deduplicate name\n if (list[id]) {\n let n = 1;\n for (; (list[`${id}-${n}`]); n++)\n ;\n id = `${id}-${n}`;\n }\n // return unique id\n return id;\n }\n // map a store by a Runtime-specific storeId\n // Stores have no intrinsic id\n addStore(storeId, store) {\n // if the store needs to discuss things with Runtime\n // TODO(sjmiles): this is likely unsafe for re-entry\n if (store.marshal) {\n store.marshal(this);\n }\n // bind to persist/restore functions\n store.persist = async () => this.persistStore(storeId, store);\n store.restore = async () => this.restoreStore(storeId, store);\n // override the Store's own persistor to use the runtime persistor\n // TODO(sjmiles): why?\n // if (store.persistor) {\n // store.persistor.persist = store => this.persistor?.persist(storeId, store);\n // }\n // bind this.storeChanged to store.change (and name the binding)\n const name = `${this.nid}:${storeId}-changed`;\n const onChange = this.storeChanged.bind(this, storeId);\n store.listen('change', onChange, name);\n // map the store\n this.stores[storeId] = store;\n // evaluate for sharing\n this.maybeShareStore(storeId);\n // notify listeners that a thing happened\n // TODO(sjmiles): makes no sense without id\n //this.fire('store-added', store);\n }\n async persistStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`persistStore \"${storeId}\"`);\n return this.persistor?.persist?.(storeId, store.data);\n }\n }\n async restoreStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`restoreStore \"${storeId}\"`);\n return this.persistor?.restore?.(storeId);\n }\n }\n storeChanged(storeId, store) {\n this.log('storeChanged', storeId);\n this.network?.invalidatePeers(storeId);\n this.onStoreChange(storeId, store);\n this.fire('store-changed', { storeId, store });\n }\n // TODO(sjmiles): evacipate this method\n onStoreChange(storeId, store) {\n // override for bespoke response\n }\n do(storeId, task) {\n task(this.stores[storeId]);\n }\n removeStore(storeId) {\n this.do(storeId, store => {\n store?.unlisten('change', `${this.nid}:${storeId}-changed`);\n });\n delete this.stores[storeId];\n }\n maybeShareStore(storeId) {\n this.do(storeId, store => {\n if (store?.is('shared')) {\n this.shareStore(storeId);\n }\n });\n }\n addPeer(peerId) {\n this.peers.add(peerId);\n [...this.shares].forEach(storeId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n shareStore(storeId) {\n this.shares.add(storeId);\n [...this.peers].forEach(peerId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n maybeShareStoreWithPeer(storeId, peerId) {\n this.do(storeId, store => {\n const nid = this.uid.replace(/\\./g, '_');\n if (!store.is('private') || (peerId.startsWith(nid))) {\n this.shareStoreWithPeer(storeId, peerId);\n }\n });\n }\n shareStoreWithPeer(storeId, peerId) {\n this.network?.shareStore(storeId, peerId);\n }\n async createParticle(host, kind) {\n try {\n const factory = await this.marshalParticleFactory(kind);\n return factory?.(host);\n }\n catch (x) {\n log.error(`createParticle(${kind}):`, x);\n }\n }\n async marshalParticleFactory(kind) {\n return particleFactoryCache[kind] ?? this.lateBindParticle(kind);\n }\n lateBindParticle(kind, code) {\n const { particleOptions, particleIndustry, registerFactoryPromise } = Runtime;\n if (!particleIndustry) {\n throw `no ParticleIndustry to create '${kind}'`;\n }\n else {\n const factoryPromise = particleIndustry(kind, { ...particleOptions, code });\n registerFactoryPromise(kind, factoryPromise);\n return factoryPromise;\n }\n }\n static registerFactoryPromise(kind, factoryPromise) {\n return particleFactoryCache[kind] = factoryPromise;\n }\n requireStore(meta) {\n let store = this.stores[meta.name];\n if (!store) {\n store = this.createStore(meta);\n this.addStore(meta.name, store);\n }\n return store;\n }\n createStore(meta) {\n const key = keys(storeFactories).find(tag => meta.tags?.includes?.(tag));\n const storeClass = storeFactories[String(key)] || Store;\n return new storeClass(meta);\n }\n static registerStoreClass(tag, storeClass) {\n storeFactories[tag] = storeClass;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'RecipeParser', 'violet');\nconst { entries, create } = Object;\nexport class Parser {\n stores;\n particles;\n slots;\n meta;\n constructor(recipe) {\n this.stores = [];\n this.particles = [];\n this.slots = [];\n this.meta = create(null);\n if (recipe) {\n this.parse(recipe);\n }\n }\n parse(recipe) {\n // `normalize` converts shorthand to longhand before parsing\n const normalized = this.normalize(recipe);\n this.parseSlotSpec(normalized, 'root', '');\n return this;\n }\n normalize(recipe) {\n if (typeof recipe !== 'object') {\n throw Error('recipe must be an Object');\n }\n // TODO(sjmiles): would be great if `normalize` normalized all the things\n return recipe;\n }\n parseSlotSpec(spec, slotName, parentName) {\n // process entries\n for (const key in spec) {\n switch (key) {\n case '$meta':\n // value is a dictionary\n this.meta = { ...this.meta, ...spec.$meta };\n break;\n case '$stores':\n // value is a StoreSpec\n this.parseStoresNode(spec.$stores);\n break;\n default: {\n // value is a ParticleSpec\n const container = parentName ? `${parentName}#${slotName}` : slotName;\n this.parseParticleSpec(container, key, spec[key]);\n break;\n }\n }\n }\n }\n parseStoresNode(stores) {\n for (const key in stores) {\n this.parseStoreSpec(key, stores[key]);\n }\n }\n parseStoreSpec(name, spec) {\n if (this.stores.find(s => s.name === name)) {\n log('duplicate store name');\n return;\n }\n const meta = {\n name,\n type: spec.$type,\n tags: spec.$tags,\n value: spec.$value\n };\n this.stores.push(meta);\n }\n parseParticleSpec(container, id, spec) {\n if (!spec.$kind) {\n log.warn(`parseParticleSpec: malformed spec has no \"kind\":`, spec);\n throw Error();\n }\n if (this.particles.find(s => s.id === id)) {\n log('duplicate particle name', id, spec);\n return;\n }\n this.particles.push({ id, container, spec });\n if (spec.$slots) {\n this.parseSlotsNode(spec.$slots, id);\n }\n }\n parseSlotsNode(slots, parent) {\n entries(slots).forEach(([key, spec]) => this.parseSlotSpec(spec, key, parent));\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport function matches(candidateMeta, targetMeta) {\n for (const property in targetMeta) {\n if (candidateMeta[property] !== targetMeta[property]) {\n return false;\n }\n }\n return true;\n}\n;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { matches } from '../utils/matching.js';\nconst log = logFactory(logFactory.flags.recipe, 'StoreCook', '#99bb15');\nconst { values } = Object;\nconst mapStore = (runtime, { name, type }) => {\n return findStores(runtime, { name, type })?.[0];\n};\nconst findStores = (runtime, criteria) => {\n return values(runtime.stores).filter(store => storeMatches(store, criteria));\n};\nconst storeMatches = (store, criteria) => {\n // TODO(b/244191110): Type matching API to be wired here.\n const { type, ...other } = criteria;\n if (typeMatches(type, store?.meta.type)) {\n // generic object comparison\n return matches(store?.meta, other);\n }\n};\nconst typeMatches = (typeA, typeB) => {\n const baseTypes = ['pojo', 'json'];\n return (typeA === typeB)\n || baseTypes.includes(typeA?.toLowerCase())\n || baseTypes.includes(typeB?.toLowerCase());\n};\nexport class StoreCook {\n static async execute(runtime, arc, stores) {\n return this.forEachStore(this.realizeStore, runtime, arc, stores);\n }\n static async evacipate(runtime, arc, stores) {\n return this.forEachStore(this.derealizeStore, runtime, arc, stores);\n }\n static async forEachStore(task, runtime, arc, stores) {\n return Promise.all(stores.map(store => task.call(this, runtime, arc, store)));\n }\n static async realizeStore(runtime, arc, rawMeta) {\n // potential initialization value\n let value;\n // build a StoreMeta out of parts\n const meta = this.constructMeta(runtime, arc, rawMeta);\n // do we already own this Store?\n let store = mapStore(runtime, meta);\n if (store) {\n // use a Store\n log(`realizeStore: mapping \"${rawMeta.name}\" to \"${store.meta.name}\"`);\n }\n else {\n log(`realizeStore: creating \"${meta.name}\"`);\n // create a Store\n store = StoreCook.createStore(runtime, meta);\n // default initial value comes from meta\n value = meta?.value;\n // persisted value may override default\n if (store.shouldPersist()) {\n const cached = await store.restore();\n value = (cached == null) ? value : cached;\n }\n }\n // we have a store for the Arc now\n arc.addStore(meta.name, store);\n // it may need a starting value\n if (value !== undefined) {\n log(`setting data to:`, value);\n store.data = value;\n }\n }\n static createStore(runtime, meta) {\n // we need to create this Store\n const store = runtime.createStore(meta);\n runtime.addStore(meta.name, store);\n return store;\n }\n static async derealizeStore(runtime, arc, meta) {\n log(`derealizeStore: derealizing \"${meta.name}\"`);\n runtime.removeStore(meta.name);\n arc.removeStore(meta.name);\n }\n static constructMeta(runtime, arc, rawMeta) {\n const meta = {\n ...rawMeta,\n arcid: arc.id,\n uid: runtime.uid,\n };\n return {\n ...meta,\n owner: meta.uid,\n shareid: `${meta.name}:${meta.arcid}:${meta.uid}`\n };\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'ParticleCook', '#5fa530');\nexport class ParticleCook {\n static async execute(runtime, arc, particles) {\n // serial\n for (const particle of particles) {\n await this.realizeParticle(runtime, arc, particle);\n }\n // parallel\n //return Promise.all(particles.map(particle => this.realizeParticle(runtime, arc, particle)));\n }\n static async realizeParticle(runtime, arc, node) {\n log('realizedParticle:', node.id);\n // convert spec to metadata\n const meta = this.specToMeta(node.spec);\n meta.container ||= node.container;\n // make a (hosted) particle\n return runtime.bootstrapParticle(arc, node.id, meta);\n }\n static specToMeta(spec) {\n if (spec.$bindings) {\n console.warn(`Particle '${spec.$kind}' spec contains deprecated $bindings property (${JSON.stringify(spec.$bindings)})`);\n }\n // TODO(sjmiles): impedance mismatch here is likely to cause problems\n const { $kind: kind, $container: container, $staticInputs: staticInputs } = spec;\n const inputs = this.formatBindings(spec.$inputs);\n const outputs = this.formatBindings(spec.$outputs);\n return { kind, staticInputs, inputs, outputs, container };\n }\n static formatBindings(bindings) {\n return bindings?.map?.(binding => typeof binding === 'string' ? { [binding]: binding } : binding);\n }\n static async evacipate(runtime, arc, particles) {\n return Promise.all(particles.map(particle => this.derealizeParticle(runtime, arc, particle)));\n }\n static async derealizeParticle(runtime, arc, node) {\n arc.removeHost(node.id);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { Parser } from './RecipeParser.js';\nimport { StoreCook } from './StoreCook.js';\nimport { ParticleCook } from './ParticleCook.js';\nconst log = logFactory(logFactory.flags.recipe, 'Chef', '#087f23');\nexport class Chef {\n static async execute(recipe, runtime, arc) {\n if (arc instanceof Promise) {\n log.error('`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.');\n return;\n }\n //log.groupCollapsed('executing recipe...', recipe.$meta);\n log('|-->...| executing recipe: ', recipe);\n const plan = new Parser(recipe);\n // `store` preparation\n await StoreCook.execute(runtime, arc, plan.stores);\n // `particle` preparation\n await ParticleCook.execute(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): what do we use this for?\n arc.meta = { ...arc.meta, ...plan.meta };\n log('|...-->| recipe complete: ', recipe.$meta ?? '');\n //log.groupEnd();\n }\n static async evacipate(recipe, runtime, arc) {\n //log.groupCollapsed('evacipating recipe...', recipe.$meta);\n log('|-->...| evacipating recipe: ', recipe.$meta);\n // TODO(sjmiles): this is work we already did\n const plan = new Parser(recipe);\n // `store` work\n // TODO(sjmiles): not sure what stores are unique to this plan\n await StoreCook.evacipate(runtime, arc, plan.stores);\n // `particle` work\n await ParticleCook.evacipate(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): doh\n //arc.meta = {...arc.meta, ...plan.meta};\n log('|...-->| recipe evacipated: ', recipe.$meta);\n //log.groupEnd();\n }\n static async executeAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.execute(recipe, runtime, arc);\n }\n }\n static async evacipateAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.evacipate(recipe, runtime, arc);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Paths } from '../utils/paths.js';\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.code, 'code', 'gold', '#333');\nconst defaultParticleBasePath = '$arcs/core/Particle.js';\n// acquire particle code\n// `kind` describes the particle\n// `options.code` may simply provide code directly\nexport const requireParticleImplCode = async (kind, options) => {\n const code = options?.code || await fetchParticleCode(kind);\n // TODO(sjmiles): brittle content processing, needs to be documented\n return code.slice(code.indexOf('({'));\n};\nexport const fetchParticleCode = async (kind) => {\n if (kind) {\n return await maybeFetchParticleCode(kind);\n }\n log.error(`fetchParticleCode: empty 'kind'`);\n};\nexport const maybeFetchParticleCode = async (kind) => {\n const path = pathForKind(kind);\n try {\n const response = await fetch(path);\n if (response.ok) {\n return await response.text();\n }\n else {\n throw '';\n }\n }\n catch (x) {\n log.error(`could not locate implementation for particle \"${kind}\" [${path}]`);\n }\n};\nexport const pathForKind = (kind) => {\n if (kind) {\n if (!'$./'.includes(kind[0]) && !kind.includes('://')) {\n kind = `$library/${kind}`;\n }\n if (!kind?.split('/').pop().includes('.')) {\n kind = `${kind}.js`;\n }\n return Paths.resolve(kind);\n }\n return '404';\n};\n// acquire Particle.js\nexport const requireParticleBaseCode = async (sourcePath) => {\n if (!requireParticleBaseCode.source) {\n const path = Paths.resolve(sourcePath || defaultParticleBasePath);\n log('particle base code path: ', path);\n const response = await fetch(path);\n const moduleText = await response.text() + \"\\n//# sourceURL=\" + path + \"\\n\";\n requireParticleBaseCode.source = moduleText.replace(/export /g, '');\n }\n return requireParticleBaseCode.source;\n};\nrequireParticleBaseCode.source = null;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const PathMapper = class {\n map;\n constructor(root) {\n this.map = {};\n this.setRoot(root);\n }\n add(mappings) {\n Object.assign(this.map, mappings || {});\n }\n resolve(path) {\n let last;\n do {\n path = this._resolve(last = path);\n } while (last !== path);\n return path;\n }\n _resolve(path) {\n const bits = path.split('/');\n const top = bits.shift();\n const prefix = this.map[top] || top;\n return [prefix, ...bits].join('/');\n }\n setRoot(root) {\n if (root.length && root[root.length - 1] === '/') {\n root = root.slice(0, -1);\n }\n this.add({\n '$root': root,\n '$arcs': root\n });\n }\n getAbsoluteHereUrl(meta, depth) {\n // you are here\n const localRelative = meta.url.split('/').slice(0, -(depth ?? 1)).join('/');\n if (!globalThis?.document) {\n return localRelative;\n }\n else {\n // document root is here\n let base = document.URL;\n // if document URL has a filename, remove it\n if (base[base.length - 1] !== '/') {\n base = `${base.split('/').slice(0, -1).join('/')}/`;\n }\n // create absoute path to here (aka 'local')\n let localAbsolute = new URL(localRelative, base).href;\n // no trailing slash!\n if (localAbsolute[localAbsolute.length - 1] === '/') {\n localAbsolute = localAbsolute.slice(0, -1);\n }\n return localAbsolute;\n }\n }\n};\nconst root = import.meta.url.split('/').slice(0, -3).join('/');\nexport const Paths = globalThis['Paths'] = new PathMapper(root);\nPaths.add(globalThis.config?.paths);\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport * from './date.js';\nexport * from './id.js';\nexport * from './log.js';\nexport * from './matching.js';\nexport * from './object.js';\nexport * from './paths.js';\nexport * from './rand.js';\nexport * from './task.js';\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const computeAgeString = (date, now) => {\n let deltaTime = Math.round((now - date) / 1000);\n if (isNaN(deltaTime)) {\n return `\u2022`;\n }\n let plural = '';\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} second${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} minute${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 24) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} hour${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 24);\n if (deltaTime < 30) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} day${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 30);\n if (deltaTime < 12) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} month${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 12);\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} year${plural} ago`;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/**\n * Perform `action` if `delay` ms have elapsed since last debounce call for `key`.\n *\n * ```\n * // invoke 'task' one second after last time this line executed\n * this.debounceTask = debounce(this.debounceTask, task, 1000);\n * ```\n */\nexport const debounce = (key, action, delay) => {\n if (key) {\n clearTimeout(key);\n }\n if (action && delay) {\n return setTimeout(action, delay);\n }\n};\nexport const async = task => {\n return async (...args) => {\n await Promise.resolve();\n task(...args);\n };\n};\nexport const asyncTask = (task, delayMs) => {\n setTimeout(task, delayMs ?? 0);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n\nexport * from '../js/Runtime.js';\nexport * from '../js/core/EventEmitter.js';\nexport * from '../js/core/Store.js';\nexport * from '../js/core/Arc.js';\nexport * from '../js/core/Host.js';\nexport * from '../js/core/Decorator.js';\nexport * from '../js/recipe/Chef.js';\nexport * from '../js/recipe/ParticleCook.js';\nexport * from '../js/recipe/StoreCook.js';\nexport * from '../js/recipe/RecipeParser.js';\nexport * as code from '../js/isolation/code.js';\n\nimport * as utils from '../js/utils/utils.js';\nconst {logFactory, Paths} = utils;\nexport {logFactory, Paths, utils};\n\nconst root = import.meta.url.split('/').slice(0, -1).join('/');\nPaths.setRoot(root);\n"], + "mappings": ";;;;;;;;;;;;AAQO,IAAM,eAAN,MAAmB;AAAA,EAEtB,YAAY,CAAC;AAAA,EACb,kBAAkB,WAAW;AACzB,WAAO,KAAK,UAAU,eAAe,KAAK,UAAU,aAAa,CAAC;AAAA,EACtE;AAAA,EACA,KAAK,cAAc,MAAM;AACrB,UAAM,YAAY,KAAK,kBAAkB,SAAS;AAClD,QAAI,WAAW,SAAS;AACpB,gBAAU,QAAQ,cAAY,SAAS,GAAG,IAAI,CAAC;AAAA,IACnD;AAAA,EACJ;AAAA,EACA,OAAO,WAAW,UAAU,cAAc;AACtC,UAAM,YAAY,KAAK,kBAAkB,SAAS;AAClD,cAAU,KAAK,QAAQ;AACvB,aAAS,QAAQ,gBAAgB;AACj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KAAK,MAAM,YAAY,EAAE;AACrC,MAAI,YAAY,IAAI;AAChB,QAAI,YAAY;AACZ,eAAS;AACb,WAAO,GAAG,mBAAmB;AAAA,EACjC;AACA,cAAY,KAAK,MAAM,YAAY,EAAE;AACrC,MAAI,YAAY,IAAI;AAChB,QAAI,YAAY;AACZ,eAAS;AACb,WAAO,GAAG,iBAAiB;AAAA,EAC/B;AACA,cAAY,KAAK,MAAM,YAAY,EAAE;AACrC,MAAI,YAAY,IAAI;AAChB,QAAI,YAAY;AACZ,eAAS;AACb,WAAO,GAAG,gBAAgB;AAAA,EAC9B;AACA,cAAY,KAAK,MAAM,YAAY,EAAE;AACrC,MAAI,YAAY,IAAI;AAChB,QAAI,YAAY;AACZ,eAAS;AACb,WAAO,GAAG,kBAAkB;AAAA,EAChC;AACA,cAAY,KAAK,MAAM,YAAY,EAAE;AACrC,MAAI,YAAY;AACZ,aAAS;AACb,SAAO,GAAG,iBAAiB;AAC/B;;;AC/BO,IAAM,WAAW,CAACC,MAAK,QAAQ,UAAU;AAC5C,MAAIA,MAAK;AACL,iBAAaA,IAAG;AAAA,EACpB;AACA,MAAI,UAAU,OAAO;AACjB,WAAO,WAAW,QAAQ,KAAK;AAAA,EACnC;AACJ;AACO,IAAM,QAAQ,UAAQ;AACzB,SAAO,UAAU,SAAS;AACtB,UAAM,QAAQ,QAAQ;AACtB,SAAK,GAAG,IAAI;AAAA,EAChB;AACJ;AACO,IAAM,YAAY,CAAC,MAAM,YAAY;AACxC,aAAW,MAAM,WAAW,CAAC;AACjC;;;ACTA,IAAM,EAAC,YAAAC,aAAY,OAAAC,OAAK,IAAI;AAG5B,IAAMC,QAAO,YAAY,IAAI,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG;AAC7DC,OAAM,QAAQD,KAAI;", "names": ["log", "output", "key", "values", "entries", "key", "entries", "keys", "customLogFactory", "key", "create", "keys", "key", "log", "keys", "key", "log", "entries", "create", "key", "log", "values", "log", "log", "root", "log", "key", "logFactory", "Paths", "root", "Paths"] } diff --git a/pkg/Library/Core/arcs.min.js b/pkg/Library/Core/arcs.min.js index 467ade6b..4cadcd43 100644 --- a/pkg/Library/Core/arcs.min.js +++ b/pkg/Library/Core/arcs.min.js @@ -1,4 +1,4 @@ -var W=Object.defineProperty;var ut=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var _=(r,t)=>{for(var e in t)W(r,e,{get:t[e],enumerable:!0})};var v=(r,t,e)=>(ut(r,typeof t!="symbol"?t+"":t,e),e);var l=class{listeners={};getEventListeners(t){return this.listeners[t]||(this.listeners[t]=[])}fire(t,...e){let s=this.getEventListeners(t);s?.forEach&&s.forEach(o=>o(...e))}listen(t,e,s){return this.getEventListeners(t).push(e),e._name=s||"(unnamed listener)",e}unlisten(t,e){let s=this.getEventListeners(t),o=typeof e=="string"?s.findIndex(i=>i._name===e):s.indexOf(e);o>=0?s.splice(o,1):console.warn("failed to unlisten from",t)}};var J=["log","group","groupCollapsed","groupEnd","dir"],V=["warn","error"];var{fromEntries:G}=Object,Q=(r,t,e,s,o="log")=>{if(typeof r=="string"&&(r=a.flags[r]),!r)return()=>{};if(o==="dir")return console.dir.bind(console);let i=`background: ${e||"gray"}; color: ${s||"white"}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;return console[o].bind(console,`%c${t}`,i)},a=(r,t,e="",s="")=>{let o=G(J.map(p=>[p,Q(r,t,e,s,p)])),i=G(V.map(p=>[p,Q(!0,t,e,s,p)])),n={...o,...i},c=n.log;return Object.assign(c,n),c};a.flags=globalThis.config?.logFlags||{};var ft=r=>a(a.flags.arc,`Arc (${r})`,"slateblue"),{assign:dt,create:gt}=Object,X=r=>Object.entries(r??Object),C=r=>Object.keys(r??Object),b=r=>Object.values(r??Object),F=()=>gt(null),w=class extends l{log;id;meta;stores;hosts;surface;composer;hostService;constructor(t,e,s){super(),this.id=t,this.meta=e,this.surface=s,this.hosts=F(),this.stores=F(),this.log=ft(t)}async addHost(t,e){return await this.ensureComposer(),this.hosts[t.id]=t,t.arc=this,this.updateHost(t),t}async ensureComposer(){!this.composer&&this.surface&&(this.composer=await this.surface.createComposer("root"),this.composer.onevent=this.onevent.bind(this))}rerender(){b(this.hosts).forEach(t=>t.rerender())}removeHost(t){this.hosts[t]?.detach(),delete this.hosts[t]}addStore(t,e){e&&!this.stores[t]&&(this.stores[t]=e,e.listen("change",()=>this.storeChanged(t,e),this.id))}removeStore(t){let e=this.stores[t];e&&e.unlisten("change",this.id),delete this.stores[t]}storeChanged(t,e){this.log(`storeChanged: "${t}"`);let s=o=>o&&o.some(i=>i&&(b(i)[0]==t||C(i)[0]==t));b(this.hosts).forEach(o=>{let i=o.meta?.inputs;(i==="*"||s(i))&&(this.log(`host "${o.id}" has interest in "${t}"`),this.updateHost(o))}),this.fire("store-changed",t)}updateParticleMeta(t,e){let s=this.hosts[t];s.meta=e,this.updateHost(s)}updateHost(t){t.inputs=this.computeInputs(t)}computeInputs(t){let e=F(),s=t.meta?.inputs;if(s==="*")X(this.stores).forEach(([o,i])=>e[o]=i.pojo);else{let o=t.meta?.staticInputs;dt(e,o),s&&(s.forEach(i=>i&&this.computeInput(X(i)[0],e)),this.log(`computeInputs(${t.id}) =`,e))}return e}computeInput([t,e],s){let o=e||t,i=this.stores[o];i&&(s[t]=i.pojo)}assignOutputs({id:t,meta:e},s){let o=C(s);e?.outputs&&o.length&&(o.forEach(i=>this.assignOutput(i,s[i],e.outputs)),this.log(`[end][${t}] assignOutputs:`,s))}assignOutput(t,e,s){if(e!==void 0){let o=this.findOutputByName(s,t)||t,i=this.stores[o];i?(this.log(`assignOutputs: "${t}" is dirty, updating Store "${o}"`,e),i.data=e):s?.[t]&&this.log.warn(`assignOutputs: no "${o}" store for output "${t}"`)}}findOutputByName(t,e){let s=t?.find(o=>C(o||0)[0]===e);if(s)return b(s)[0]}async render(t){this.composer&&this.composer.render({...t,arcid:this.id})}onevent(t,e){let s=this.hosts[t];s&&s.handleEvent(e)}async service(t,e){let s=await this.surface?.service(e);return s===void 0&&(s=this.hostService?.(t,e)),s}};var mt=(r,t)=>{let e=t;if(t){if(Array.isArray(t)){Array.isArray(r)||(r=[]);for(let o=0;o0&&r.splice(t.length,s)}else if(typeof t=="object"){e=r&&typeof r=="object"?r:Object.create(null);let s={};Object.keys(t).forEach(o=>{e[o]=t[o],s[o]=!0}),Object.keys(e).forEach(o=>{s[o]||delete e[o]})}}return e},yt=(r,t)=>{if(t==null)return null;if(typeof t=="object"){let e=r&&typeof r=="object"?r:Object.create(null);return Object.keys(t).forEach(s=>e[s]=t[s]),e}return t};function h(r){if(r){if(Array.isArray(r))return r.map(t=>h(t));if(typeof r=="object"){let t=Object.create(null);return Object.entries(r).forEach(([e,s])=>{t[e]=h(s)}),t}else return r}else return r}var f=(r,t)=>{let e=typeof r;if(e!==typeof t)return!1;if(e==="object"&&r&&t){let s=Object.getOwnPropertyNames(r),o=Object.getOwnPropertyNames(t);return s.length==o.length&&!s.some(i=>!f(r[i],t[i]))}return r===t},Y=r=>r===void 0?null:(r&&typeof r=="object"&&Object.getOwnPropertyNames(r).forEach(e=>{let s=r[e];s===void 0?delete r[e]:Y(s)}),r);var{floor:Z,pow:$t,random:D}=Math,xt=r=>Z((1+D()*9)*$t(10,r-1)),O=r=>Z(D()*r),z=r=>r[O(r.length)],St=r=>Boolean(D(){e&&typeof e=="object"&&(e.models?(A("applying decorator(s) to list:",e),this.maybeDecorateItem(e,t)):(r?.filter||r?.decorator||r?.collateBy)&&(A("scanning for lists in sub-model:",e),this.maybeDecorateModel(e,t)))}),r},maybeDecorateItem(r,t){let e=typeof r.models=="string"?this.getOpaqueData(r.models):r.models;e&&(e=vt(e,r.decorator,t),e=bt(e,r.filter,t.impl),e=wt(e,r),r.models=e)}},vt=(r,t,e)=>{t=e.impl[t]??t;let{inputs:s,state:o}=e.internal;if(t){let i=Object.freeze(h(s)),n=Object.freeze(h(o));r=r.map(c=>{c.privateData=c.privateData||{};let p=Object.freeze(h(c)),K=t(p,i,n);return c.privateData=K.privateData,{...K,...c}}),r.sort(Ot("sortKey")),A("decoration was performed")}return r},bt=(r,t,e)=>(t=e[t]??t,t&&r&&(r=r.filter(t)),r),wt=(r,t)=>(tt(t).forEach(([e,s])=>{if(s?.collateBy){let o=Et(r,s.collateBy);r=Ct(o,e,s.$template)}}),r),Ot=r=>(t,e)=>jt(String(t[r]).toLowerCase(),String(e[r]).toLowerCase()),jt=(r,t)=>rt?1:0,Et=(r,t)=>{let e={};return r.forEach(s=>{let o=s[t];o&&(e[o]||(e[o]=[])).push(s)}),e},Ct=(r,t,e)=>tt(r).map(([s,o])=>({key:s,[t]:{models:o,$template:e},single:o.length===1,...o?.[0]}));var{entries:et,keys:Ft}=Object,Dt=r=>a(a.flags.host,`Host (${r})`,z(["#5a189a","#51168b","#48137b","#6b2fa4","#7b46ae","#3f116c"])),d=class extends l{arc;id;lastOutput;lastPacket;lastRenderModel;log;meta;particle;constructor(t){super(),this.log=Dt(t),this.id=t}onevent(t){this.arc?.onevent(t),this.fire("eventlet",t)}installParticle(t,e){this.particle&&this.detachParticle(),t&&(this.particle=t,this.meta=e||this.meta)}get container(){return this.meta?.container||"root"}detach(){this.detachParticle(),this.arc=null}detachParticle(){this.particle&&(this.render({$clear:!0}),this.particle=null,this.meta=null)}async service(t){return t?.decorate?L.maybeDecorateModel(t.model,this.particle):this.arc?.service(this,t)}output(t,e){t&&(this.lastOutput=t,this.arc?.assignOutputs(this,t),this.fire("output",t)),this.template&&(L.maybeDecorateModel(e,this.particle),this.lastRenderModel={...e},this.render(e))}rerender(){this.lastRenderModel&&this.render(this.lastRenderModel)}render(t){let{id:e,container:s,template:o}=this,n={id:e,container:s,content:{model:t,template:o}};this.fire("render",n),this.arc?.render(n),this.lastPacket=n}set inputs(t){if(this.particle&&t){let e=this.particle.internal.inputs;this.dirtyCheck(t,e,this.lastOutput)?(this.particle.inputs=h({...this.meta?.staticInputs,...t}),this.fire("inputs-changed")):this.log("inputs are uninteresting, skipping update")}}dirtyCheck(t,e,s){let o=([i,n])=>s?.[i]&&!f(s[i],n)||!f(e?.[i],n);return!e||et(t).length!==this.lastInputsLength(e)||et(t).some(o)}lastInputsLength(t){return Ft(t).filter(e=>!this.meta?.staticInputs?.[e]&&e!=="eventlet").length}get config(){return this.particle?.config}get template(){return this.config?.template}invalidate(){this.particle?.invalidate()}handleEvent(t){return this.particle?.handleEvent(t)}};var{create:zt,keys:At}=Object,{stringify:st,parse:rt}=JSON,M=class extends l{privateData;constructor(){super()}setPrivateData(t){this.privateData=t}set data(t){this.setPrivateData(t)}get data(){return this.privateData}toString(){return this.pretty}get isObject(){return this.data&&typeof this.data=="object"}get pojo(){return this.data}get json(){return st(this.data)}set json(t){let e=null;try{e=rt(t)}catch{}this.data=e}get pretty(){let t={},e=this.pojo;return At(e).sort().forEach(s=>t[s]=e[s]),st(t,null," ")}},B=class extends M{change(t){t(this),this.doChange()}doChange(){this.fire("change",this),this.onChange(this)}onChange(t){}set data(t){this.change(e=>e.setPrivateData(t))}get data(){return this.privateData}set(t,e){this.data||this.setPrivateData(zt(null)),e!==void 0?this.change(s=>s.data[t]=e):this.delete(t)}delete(t){this.change(e=>delete e.data[t])}},T=class extends B{meta;constructor(t){super(),this.meta={...t}}toString(){return`${JSON.stringify(this.meta,null," ")}, ${this.pretty}`}get tags(){return this.meta.tags??(this.meta.tags=[])}is(...t){return t.every(e=>this.tags.includes(e))}isCollection(){return this.meta.type?.[0]==="["}shouldPersist(){return this.is("persisted")&&!this.is("volatile")}async doChange(){return this.persist(),super.doChange()}async persist(){}async restore(){}save(){return this.json}load(t,e){let s=e;try{t&&(s=rt(t))}catch{}s!==void 0&&(this.data=s)}},j=class extends T{};var g=(r,t,e)=>{r=r||2,t=t||2,e=e||"-";let s=Math.pow(10,t-1),o=Math.pow(10,t)-s,i=[];for(let n=0;nt.handle(this,e,s)}async bootstrapParticle(t,e,s){let o=new d(e);return await this.marshalParticle(o,s),await t.addHost(o),ot("bootstrapped particle",e),o}addSurface(t,e){this.surfaces[t]=e}getSurface(t){return this.surfaces[t]}addArc(t){let{id:e}=t;if(e&&!this.arcs[e])return this.arcs[e]=t;throw`arc has no id, or id "${e}" is already in use`}removeArc(t){let{id:e}=t;if(!e||!this.arcs[e])throw e?`id "${e}" is not in use`:"arc has no id";delete this.arcs[e]}async marshalParticle(t,e){let s=await this.createParticle(t,e.kind);return t.installParticle(s,e)}async installParticle(t,e,s){if(this.log("installParticle",s,e,t.id),s=s||g(),t.hosts[s]){let i=1;for(;t.hosts[`${s}-${i}`];i++);s=`${s}-${i}`}let o=new d(s);return await this.marshalParticle(o,e),await t.addHost(o),o}async addParticle(t,e,s,o){return this.log("addParticle",t.id,o,s,t.id),await this.marshalParticle(e,s),await t.addHost(e),e}idFromName(t,e){let s=t||g();if(e[s]){let o=1;for(;e[`${s}-${o}`];o++);s=`${s}-${o}`}return s}addStore(t,e){e.marshal&&e.marshal(this),e.persist=async()=>this.persistStore(t,e),e.restore=async()=>this.restoreStore(t,e);let s=`${this.nid}:${t}-changed`,o=this.storeChanged.bind(this,t);e.listen("change",o,s),this.stores[t]=e,this.maybeShareStore(t)}async persistStore(t,e){if(e.shouldPersist())return this.log(`persistStore "${t}"`),this.persistor?.persist?.(t,e.data)}async restoreStore(t,e){if(e.shouldPersist())return this.log(`restoreStore "${t}"`),this.persistor?.restore?.(t)}storeChanged(t,e){this.log("storeChanged",t),this.network?.invalidatePeers(t),this.onStoreChange(t,e),this.fire("store-changed",{storeId:t,store:e})}onStoreChange(t,e){}do(t,e){e(this.stores[t])}removeStore(t){this.do(t,e=>{e?.unlisten("change",`${this.nid}:${t}-changed`)}),delete this.stores[t]}maybeShareStore(t){this.do(t,e=>{e?.is("shared")&&this.shareStore(t)})}addPeer(t){this.peers.add(t),[...this.shares].forEach(e=>this.maybeShareStoreWithPeer(e,t))}shareStore(t){this.shares.add(t),[...this.peers].forEach(e=>this.maybeShareStoreWithPeer(t,e))}maybeShareStoreWithPeer(t,e){this.do(t,s=>{let o=this.uid.replace(/\./g,"_");(!s.is("private")||e.startsWith(o))&&this.shareStoreWithPeer(t,e)})}shareStoreWithPeer(t,e){this.network?.shareStore(t,e)}async createParticle(t,e){try{return(await this.marshalParticleFactory(e))?.(t)}catch(s){ot.error(`createParticle(${e}):`,s)}}async marshalParticleFactory(t){return it[t]??this.lateBindParticle(t)}lateBindParticle(t,e){let{particleOptions:s,particleIndustry:o,registerFactoryPromise:i}=N;if(o){let n=o(t,{...s,code:e});return i(t,n),n}else throw`no ParticleIndustry to create '${t}'`}static registerFactoryPromise(t,e){return it[t]=e}requireStore(t){let e=this.stores[t.name];return e||(e=this.createStore(t),this.addStore(t.name,e)),e}createStore(t){let e=Lt(k).find(o=>t.tags?.includes?.(o)),s=k[String(e)]||j;return new s(t)}static registerStoreClass(t,e){k[t]=e}},m=N;v(m,"securityLockdown"),v(m,"particleIndustry"),v(m,"particleOptions");var H=a(a.flags.recipe,"RecipeParser","violet"),{entries:Mt,create:Bt}=Object,y=class{stores;particles;slots;meta;constructor(t){this.stores=[],this.particles=[],this.slots=[],this.meta=Bt(null),t&&this.parse(t)}parse(t){let e=this.normalize(t);return this.parseSlotSpec(e,"root",""),this}normalize(t){if(typeof t!="object")throw Error("recipe must be an Object");return t}parseSlotSpec(t,e,s){for(let o in t)switch(o){case"$meta":this.meta={...this.meta,...t.$meta};break;case"$stores":this.parseStoresNode(t.$stores);break;default:{let i=s?`${s}#${e}`:e;this.parseParticleSpec(i,o,t[o]);break}}}parseStoresNode(t){for(let e in t)this.parseStoreSpec(e,t[e])}parseStoreSpec(t,e){if(this.stores.find(o=>o.name===t)){H("duplicate store name");return}let s={name:t,type:e.$type,tags:e.$tags,value:e.$value};this.stores.push(s)}parseParticleSpec(t,e,s){if(!s.$kind)throw H.warn('parseParticleSpec: malformed spec has no "kind":',s),Error();if(this.particles.find(o=>o.id===e)){H("duplicate particle name",e,s);return}this.particles.push({id:e,container:t,spec:s}),s.$slots&&this.parseSlotsNode(s.$slots,e)}parseSlotsNode(t,e){Mt(t).forEach(([s,o])=>this.parseSlotSpec(o,s,e))}};function U(r,t){for(let e in t)if(r[e]!==t[e])return!1;return!0}var E=a(a.flags.recipe,"StoreCook","#99bb15"),{values:Tt}=Object,kt=(r,{name:t,type:e})=>Nt(r,{name:t,type:e})?.[0],Nt=(r,t)=>Tt(r.stores).filter(e=>Ht(e,t)),Ht=(r,t)=>{let{type:e,...s}=t;if(Ut(e,r?.meta.type))return U(r?.meta,s)},Ut=(r,t)=>{let e=["pojo","json"];return r===t||e.includes(r?.toLowerCase())||e.includes(t?.toLowerCase())},u=class{static async execute(t,e,s){return this.forEachStore(this.realizeStore,t,e,s)}static async evacipate(t,e,s){return this.forEachStore(this.derealizeStore,t,e,s)}static async forEachStore(t,e,s,o){return Promise.all(o.map(i=>t.call(this,e,s,i)))}static async realizeStore(t,e,s){let o,i=this.constructMeta(t,e,s),n=kt(t,i);if(n)E(`realizeStore: mapping "${s.name}" to "${n.meta.name}"`);else if(E(`realizeStore: creating "${i.name}"`),n=u.createStore(t,i),o=i?.value,n.shouldPersist()){let c=await n.restore();o=c??o}e.addStore(i.name,n),o!==void 0&&(E("setting data to:",o),n.data=o)}static createStore(t,e){let s=t.createStore(e);return t.addStore(e.name,s),s}static async derealizeStore(t,e,s){E(`derealizeStore: derealizing "${s.name}"`),t.removeStore(s.name),e.removeStore(s.name)}static constructMeta(t,e,s){let o={...s,arcid:e.id,uid:t.uid};return{...o,owner:o.uid,shareid:`${o.name}:${o.arcid}:${o.uid}`}}};var Rt=a(a.flags.recipe,"ParticleCook","#5fa530"),$=class{static async execute(t,e,s){for(let o of s)await this.realizeParticle(t,e,o)}static async realizeParticle(t,e,s){Rt("realizedParticle:",s.id);let o=this.specToMeta(s.spec);return o.container||=s.container,t.bootstrapParticle(e,s.id,o)}static specToMeta(t){t.$bindings&&console.warn(`Particle '${t.$kind}' spec contains deprecated $bindings property (${JSON.stringify(t.$bindings)})`);let{$kind:e,$container:s,$staticInputs:o}=t,i=this.formatBindings(t.$inputs),n=this.formatBindings(t.$outputs);return{kind:e,staticInputs:o,inputs:i,outputs:n,container:s}}static formatBindings(t){return t?.map?.(e=>typeof e=="string"?{[e]:e}:e)}static async evacipate(t,e,s){return Promise.all(s.map(o=>this.derealizeParticle(t,e,o)))}static async derealizeParticle(t,e,s){e.removeHost(s.id)}};var x=a(a.flags.recipe,"Chef","#087f23"),at=class{static async execute(t,e,s){if(s instanceof Promise){x.error("`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.");return}x("|-->...| executing recipe: ",t.$meta??"");let o=new y(t);await u.execute(e,s,o.stores),await $.execute(e,s,o.particles),s.meta={...s.meta,...o.meta},x("|...-->| recipe complete: ",t.$meta??"")}static async evacipate(t,e,s){x("|-->...| evacipating recipe: ",t.$meta);let o=new y(t);await u.evacipate(e,s,o.stores),await $.evacipate(e,s,o.particles),x("|...-->| recipe evacipated: ",t.$meta)}static async executeAll(t,e,s){for(let o of t)await this.execute(o,e,s)}static async evacipateAll(t,e,s){for(let o of t)await this.evacipate(o,e,s)}};var pt={};_(pt,{fetchParticleCode:()=>ct,maybeFetchParticleCode:()=>lt,pathForKind:()=>ht,requireParticleBaseCode:()=>P,requireParticleImplCode:()=>Wt});var nt=class{map;constructor(r){this.map={},this.setRoot(r)}add(r){Object.assign(this.map,r||{})}resolve(r){let t;do r=this._resolve(t=r);while(t!==r);return r}_resolve(r){let t=r.split("/"),e=t.shift();return[this.map[e]||e,...t].join("/")}setRoot(r){r.length&&r[r.length-1]==="/"&&(r=r.slice(0,-1)),this.add({$root:r,$arcs:r})}getAbsoluteHereUrl(r,t){let e=r.url.split("/").slice(0,-(t??1)).join("/");if(globalThis?.document){let s=document.URL;s[s.length-1]!=="/"&&(s=`${s.split("/").slice(0,-1).join("/")}/`);let o=new URL(e,s).href;return o[o.length-1]==="/"&&(o=o.slice(0,-1)),o}else return e}},qt=import.meta.url.split("/").slice(0,-3).join("/"),S=globalThis.Paths=new nt(qt);S.add(globalThis.config?.paths);var R=a(a.flags.code,"code","gold","#333"),Kt="$arcs/core/Particle.js",Wt=async(r,t)=>{let e=t?.code||await ct(r);return e.slice(e.indexOf("({"))},ct=async r=>{if(r)return await lt(r);R.error("fetchParticleCode: empty 'kind'")},lt=async r=>{let t=ht(r);try{let e=await fetch(t);if(e.ok)return await e.text();throw""}catch{R.error(`could not locate implementation for particle "${r}" [${t}]`)}},ht=r=>r?(!"$./".includes(r[0])&&!r.includes("://")&&(r=`$library/${r}`),r?.split("/").pop().includes(".")||(r=`${r}.js`),S.resolve(r)):"404",P=async r=>{if(!P.source){let t=S.resolve(r||Kt);R("particle base code path: ",t);let s=await(await fetch(t)).text()+` +var W=Object.defineProperty;var ut=(r,t,e)=>t in r?W(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var _=(r,t)=>{for(var e in t)W(r,e,{get:t[e],enumerable:!0})};var v=(r,t,e)=>(ut(r,typeof t!="symbol"?t+"":t,e),e);var l=class{listeners={};getEventListeners(t){return this.listeners[t]||(this.listeners[t]=[])}fire(t,...e){let s=this.getEventListeners(t);s?.forEach&&s.forEach(o=>o(...e))}listen(t,e,s){return this.getEventListeners(t).push(e),e._name=s||"(unnamed listener)",e}unlisten(t,e){let s=this.getEventListeners(t),o=typeof e=="string"?s.findIndex(i=>i._name===e):s.indexOf(e);o>=0?s.splice(o,1):console.warn("failed to unlisten from",t)}};var J=["log","group","groupCollapsed","groupEnd","dir"],V=["warn","error"];var{fromEntries:G}=Object,Q=(r,t,e,s,o="log")=>{if(typeof r=="string"&&(r=a.flags[r]),!r)return()=>{};if(o==="dir")return console.dir.bind(console);let i=`background: ${e||"gray"}; color: ${s||"white"}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;return console[o].bind(console,`%c${t}`,i)},a=(r,t,e="",s="")=>{let o=G(J.map(p=>[p,Q(r,t,e,s,p)])),i=G(V.map(p=>[p,Q(!0,t,e,s,p)])),n={...o,...i},c=n.log;return Object.assign(c,n),c};a.flags=globalThis.config?.logFlags||{};var ft=r=>a(a.flags.arc,`Arc (${r})`,"slateblue"),{assign:dt,create:gt}=Object,X=r=>Object.entries(r??Object),C=r=>Object.keys(r??Object),b=r=>Object.values(r??Object),F=()=>gt(null),w=class extends l{log;id;meta;stores;hosts;surface;composer;hostService;constructor(t,e,s){super(),this.id=t,this.meta=e,this.surface=s,this.hosts=F(),this.stores=F(),this.log=ft(t)}async addHost(t,e){return await this.ensureComposer(),this.hosts[t.id]=t,t.arc=this,this.updateHost(t),t}async ensureComposer(){!this.composer&&this.surface&&(this.composer=await this.surface.createComposer("root"),this.composer.onevent=this.onevent.bind(this))}rerender(){b(this.hosts).forEach(t=>t.rerender())}removeHost(t){this.hosts[t]?.detach(),delete this.hosts[t]}addStore(t,e){e&&!this.stores[t]&&(this.stores[t]=e,e.listen("change",()=>this.storeChanged(t,e),this.id))}removeStore(t){let e=this.stores[t];e&&e.unlisten("change",this.id),delete this.stores[t]}storeChanged(t,e){this.log(`storeChanged: "${t}"`);let s=o=>o&&o.some(i=>i&&(b(i)[0]==t||C(i)[0]==t));b(this.hosts).forEach(o=>{let i=o.meta?.inputs;(i==="*"||s(i))&&(this.log(`host "${o.id}" has interest in "${t}"`),this.updateHost(o))}),this.fire("store-changed",t)}updateParticleMeta(t,e){let s=this.hosts[t];s.meta=e,this.updateHost(s)}updateHost(t){t.inputs=this.computeInputs(t)}computeInputs(t){let e=F(),s=t.meta?.inputs;if(s==="*")X(this.stores).forEach(([o,i])=>e[o]=i.pojo);else{let o=t.meta?.staticInputs;dt(e,o),s&&(s.forEach(i=>i&&this.computeInput(X(i)[0],e)),this.log(`computeInputs(${t.id}) =`,e))}return e}computeInput([t,e],s){let o=e||t,i=this.stores[o];i&&(s[t]=i.pojo)}assignOutputs({id:t,meta:e},s){let o=C(s);e?.outputs&&o.length&&(o.forEach(i=>this.assignOutput(i,s[i],e.outputs)),this.log(`[end][${t}] assignOutputs:`,s))}assignOutput(t,e,s){if(e!==void 0){let o=this.findOutputByName(s,t)||t,i=this.stores[o];i?(this.log(`assignOutputs: "${t}" is dirty, updating Store "${o}"`,e),i.data=e):s?.[t]&&this.log.warn(`assignOutputs: no "${o}" store for output "${t}"`)}}findOutputByName(t,e){let s=t?.find(o=>C(o||0)[0]===e);if(s)return b(s)[0]}async render(t){this.composer&&this.composer.render({...t,arcid:this.id})}onevent(t,e){let s=this.hosts[t];s&&s.handleEvent(e)}async service(t,e){let s=await this.surface?.service(e);return s===void 0&&(s=this.hostService?.(t,e)),s}};var mt=(r,t)=>{let e=t;if(t){if(Array.isArray(t)){Array.isArray(r)||(r=[]);for(let o=0;o0&&r.splice(t.length,s)}else if(typeof t=="object"){e=r&&typeof r=="object"?r:Object.create(null);let s={};Object.keys(t).forEach(o=>{e[o]=t[o],s[o]=!0}),Object.keys(e).forEach(o=>{s[o]||delete e[o]})}}return e},yt=(r,t)=>{if(t==null)return null;if(typeof t=="object"){let e=r&&typeof r=="object"?r:Object.create(null);return Object.keys(t).forEach(s=>e[s]=t[s]),e}return t};function h(r){if(r){if(Array.isArray(r))return r.map(t=>h(t));if(typeof r=="object"){let t=Object.create(null);return Object.entries(r).forEach(([e,s])=>{t[e]=h(s)}),t}else return r}else return r}var f=(r,t)=>{let e=typeof r;if(e!==typeof t)return!1;if(e==="object"&&r&&t){let s=Object.getOwnPropertyNames(r),o=Object.getOwnPropertyNames(t);return s.length==o.length&&!s.some(i=>!f(r[i],t[i]))}return r===t},Y=r=>r===void 0?null:(r&&typeof r=="object"&&Object.getOwnPropertyNames(r).forEach(e=>{let s=r[e];s===void 0?delete r[e]:Y(s)}),r);var{floor:Z,pow:$t,random:D}=Math,xt=r=>Z((1+D()*9)*$t(10,r-1)),O=r=>Z(D()*r),z=r=>r[O(r.length)],St=r=>Boolean(D(){e&&typeof e=="object"&&(e.models?(A("applying decorator(s) to list:",e),this.maybeDecorateItem(e,t)):(r?.filter||r?.decorator||r?.collateBy)&&(A("scanning for lists in sub-model:",e),this.maybeDecorateModel(e,t)))}),r},maybeDecorateItem(r,t){let e=typeof r.models=="string"?this.getOpaqueData(r.models):r.models;e&&(e=vt(e,r.decorator,t),e=bt(e,r.filter,t.impl),e=wt(e,r),r.models=e)}},vt=(r,t,e)=>{t=e.impl[t]??t;let{inputs:s,state:o}=e.internal;if(t){let i=Object.freeze(h(s)),n=Object.freeze(h(o));r=r.map(c=>{c.privateData=c.privateData||{};let p=Object.freeze(h(c)),K=t(p,i,n);return c.privateData=K.privateData,{...K,...c}}),r.sort(Ot("sortKey")),A("decoration was performed")}return r},bt=(r,t,e)=>(t=e[t]??t,t&&r&&(r=r.filter(t)),r),wt=(r,t)=>(tt(t).forEach(([e,s])=>{if(s?.collateBy){let o=Et(r,s.collateBy);r=Ct(o,e,s.$template)}}),r),Ot=r=>(t,e)=>jt(String(t[r]).toLowerCase(),String(e[r]).toLowerCase()),jt=(r,t)=>rt?1:0,Et=(r,t)=>{let e={};return r.forEach(s=>{let o=s[t];o&&(e[o]||(e[o]=[])).push(s)}),e},Ct=(r,t,e)=>tt(r).map(([s,o])=>({key:s,[t]:{models:o,$template:e},single:o.length===1,...o?.[0]}));var{entries:et,keys:Ft}=Object,Dt=r=>a(a.flags.host,`Host (${r})`,z(["#5a189a","#51168b","#48137b","#6b2fa4","#7b46ae","#3f116c"])),d=class extends l{arc;id;lastOutput;lastPacket;lastRenderModel;log;meta;particle;constructor(t){super(),this.log=Dt(t),this.id=t}onevent(t){this.arc?.onevent(t),this.fire("eventlet",t)}installParticle(t,e){this.particle&&this.detachParticle(),t&&(this.particle=t,this.meta=e||this.meta)}get container(){return this.meta?.container||"root"}detach(){this.detachParticle(),this.arc=null}detachParticle(){this.particle&&(this.render({$clear:!0}),this.particle=null,this.meta=null)}async service(t){return t?.decorate?L.maybeDecorateModel(t.model,this.particle):this.arc?.service(this,t)}output(t,e){t&&(this.lastOutput=t,this.arc?.assignOutputs(this,t),this.fire("output",t)),this.template&&(L.maybeDecorateModel(e,this.particle),this.lastRenderModel={...e},this.render(e))}rerender(){this.lastRenderModel&&this.render(this.lastRenderModel)}render(t){let{id:e,container:s,template:o}=this,n={id:e,container:s,content:{model:t,template:o}};this.fire("render",n),this.arc?.render(n),this.lastPacket=n}set inputs(t){if(this.particle&&t){let e=this.particle.internal.inputs;this.dirtyCheck(t,e,this.lastOutput)?(this.particle.inputs=h({...this.meta?.staticInputs,...t}),this.fire("inputs-changed")):this.log("inputs are uninteresting, skipping update")}}dirtyCheck(t,e,s){let o=([i,n])=>s?.[i]&&!f(s[i],n)||!f(e?.[i],n);return!e||et(t).length!==this.lastInputsLength(e)||et(t).some(o)}lastInputsLength(t){return Ft(t).filter(e=>!this.meta?.staticInputs?.[e]&&e!=="eventlet").length}get config(){return this.particle?.config}get template(){return this.config?.template}invalidate(){this.particle?.invalidate()}handleEvent(t){return this.particle?.handleEvent(t)}};var{create:zt,keys:At}=Object,{stringify:st,parse:rt}=JSON,M=class extends l{privateData;constructor(){super()}setPrivateData(t){this.privateData=t}set data(t){this.setPrivateData(t)}get data(){return this.privateData}toString(){return this.pretty}get isObject(){return this.data&&typeof this.data=="object"}get pojo(){return this.data}get json(){return st(this.data)}set json(t){let e=null;try{e=rt(t)}catch{}this.data=e}get pretty(){let t={},e=this.pojo;return At(e).sort().forEach(s=>t[s]=e[s]),st(t,null," ")}},B=class extends M{change(t){t(this),this.doChange()}doChange(){this.fire("change",this),this.onChange(this)}onChange(t){}set data(t){this.change(e=>e.setPrivateData(t))}get data(){return this.privateData}set(t,e){this.data||this.setPrivateData(zt(null)),e!==void 0?this.change(s=>s.data[t]=e):this.delete(t)}delete(t){this.change(e=>delete e.data[t])}},T=class extends B{meta;constructor(t){super(),this.meta={...t}}toString(){return`${JSON.stringify(this.meta,null," ")}, ${this.pretty}`}get tags(){return this.meta.tags??(this.meta.tags=[])}is(...t){return t.every(e=>this.tags.includes(e))}isCollection(){return this.meta.type?.[0]==="["}shouldPersist(){return this.is("persisted")&&!this.is("volatile")}async doChange(){return this.persist(),super.doChange()}async persist(){}async restore(){}save(){return this.json}load(t,e){let s=e;try{t&&(s=rt(t))}catch{}s!==void 0&&(this.data=s)}},j=class extends T{};var g=(r,t,e)=>{r=r||2,t=t||2,e=e||"-";let s=Math.pow(10,t-1),o=Math.pow(10,t)-s,i=[];for(let n=0;nt.handle(this,e,s)}async bootstrapParticle(t,e,s){let o=new d(e);return await this.marshalParticle(o,s),await t.addHost(o),ot("bootstrapped particle",e),o}addSurface(t,e){this.surfaces[t]=e}getSurface(t){return this.surfaces[t]}addArc(t){let{id:e}=t;if(e&&!this.arcs[e])return this.arcs[e]=t;throw`arc has no id, or id "${e}" is already in use`}removeArc(t){let{id:e}=t;if(!e||!this.arcs[e])throw e?`id "${e}" is not in use`:"arc has no id";delete this.arcs[e]}async marshalParticle(t,e){let s=await this.createParticle(t,e.kind);return t.installParticle(s,e)}async installParticle(t,e,s){if(this.log("installParticle",s,e,t.id),s=s||g(),t.hosts[s]){let i=1;for(;t.hosts[`${s}-${i}`];i++);s=`${s}-${i}`}let o=new d(s);return await this.marshalParticle(o,e),await t.addHost(o),o}async addParticle(t,e,s,o){return this.log("addParticle",t.id,o,s,t.id),await this.marshalParticle(e,s),await t.addHost(e),e}idFromName(t,e){let s=t||g();if(e[s]){let o=1;for(;e[`${s}-${o}`];o++);s=`${s}-${o}`}return s}addStore(t,e){e.marshal&&e.marshal(this),e.persist=async()=>this.persistStore(t,e),e.restore=async()=>this.restoreStore(t,e);let s=`${this.nid}:${t}-changed`,o=this.storeChanged.bind(this,t);e.listen("change",o,s),this.stores[t]=e,this.maybeShareStore(t)}async persistStore(t,e){if(e.shouldPersist())return this.log(`persistStore "${t}"`),this.persistor?.persist?.(t,e.data)}async restoreStore(t,e){if(e.shouldPersist())return this.log(`restoreStore "${t}"`),this.persistor?.restore?.(t)}storeChanged(t,e){this.log("storeChanged",t),this.network?.invalidatePeers(t),this.onStoreChange(t,e),this.fire("store-changed",{storeId:t,store:e})}onStoreChange(t,e){}do(t,e){e(this.stores[t])}removeStore(t){this.do(t,e=>{e?.unlisten("change",`${this.nid}:${t}-changed`)}),delete this.stores[t]}maybeShareStore(t){this.do(t,e=>{e?.is("shared")&&this.shareStore(t)})}addPeer(t){this.peers.add(t),[...this.shares].forEach(e=>this.maybeShareStoreWithPeer(e,t))}shareStore(t){this.shares.add(t),[...this.peers].forEach(e=>this.maybeShareStoreWithPeer(t,e))}maybeShareStoreWithPeer(t,e){this.do(t,s=>{let o=this.uid.replace(/\./g,"_");(!s.is("private")||e.startsWith(o))&&this.shareStoreWithPeer(t,e)})}shareStoreWithPeer(t,e){this.network?.shareStore(t,e)}async createParticle(t,e){try{return(await this.marshalParticleFactory(e))?.(t)}catch(s){ot.error(`createParticle(${e}):`,s)}}async marshalParticleFactory(t){return it[t]??this.lateBindParticle(t)}lateBindParticle(t,e){let{particleOptions:s,particleIndustry:o,registerFactoryPromise:i}=N;if(o){let n=o(t,{...s,code:e});return i(t,n),n}else throw`no ParticleIndustry to create '${t}'`}static registerFactoryPromise(t,e){return it[t]=e}requireStore(t){let e=this.stores[t.name];return e||(e=this.createStore(t),this.addStore(t.name,e)),e}createStore(t){let e=Lt(k).find(o=>t.tags?.includes?.(o)),s=k[String(e)]||j;return new s(t)}static registerStoreClass(t,e){k[t]=e}},m=N;v(m,"securityLockdown"),v(m,"particleIndustry"),v(m,"particleOptions");var H=a(a.flags.recipe,"RecipeParser","violet"),{entries:Mt,create:Bt}=Object,y=class{stores;particles;slots;meta;constructor(t){this.stores=[],this.particles=[],this.slots=[],this.meta=Bt(null),t&&this.parse(t)}parse(t){let e=this.normalize(t);return this.parseSlotSpec(e,"root",""),this}normalize(t){if(typeof t!="object")throw Error("recipe must be an Object");return t}parseSlotSpec(t,e,s){for(let o in t)switch(o){case"$meta":this.meta={...this.meta,...t.$meta};break;case"$stores":this.parseStoresNode(t.$stores);break;default:{let i=s?`${s}#${e}`:e;this.parseParticleSpec(i,o,t[o]);break}}}parseStoresNode(t){for(let e in t)this.parseStoreSpec(e,t[e])}parseStoreSpec(t,e){if(this.stores.find(o=>o.name===t)){H("duplicate store name");return}let s={name:t,type:e.$type,tags:e.$tags,value:e.$value};this.stores.push(s)}parseParticleSpec(t,e,s){if(!s.$kind)throw H.warn('parseParticleSpec: malformed spec has no "kind":',s),Error();if(this.particles.find(o=>o.id===e)){H("duplicate particle name",e,s);return}this.particles.push({id:e,container:t,spec:s}),s.$slots&&this.parseSlotsNode(s.$slots,e)}parseSlotsNode(t,e){Mt(t).forEach(([s,o])=>this.parseSlotSpec(o,s,e))}};function U(r,t){for(let e in t)if(r[e]!==t[e])return!1;return!0}var E=a(a.flags.recipe,"StoreCook","#99bb15"),{values:Tt}=Object,kt=(r,{name:t,type:e})=>Nt(r,{name:t,type:e})?.[0],Nt=(r,t)=>Tt(r.stores).filter(e=>Ht(e,t)),Ht=(r,t)=>{let{type:e,...s}=t;if(Ut(e,r?.meta.type))return U(r?.meta,s)},Ut=(r,t)=>{let e=["pojo","json"];return r===t||e.includes(r?.toLowerCase())||e.includes(t?.toLowerCase())},u=class{static async execute(t,e,s){return this.forEachStore(this.realizeStore,t,e,s)}static async evacipate(t,e,s){return this.forEachStore(this.derealizeStore,t,e,s)}static async forEachStore(t,e,s,o){return Promise.all(o.map(i=>t.call(this,e,s,i)))}static async realizeStore(t,e,s){let o,i=this.constructMeta(t,e,s),n=kt(t,i);if(n)E(`realizeStore: mapping "${s.name}" to "${n.meta.name}"`);else if(E(`realizeStore: creating "${i.name}"`),n=u.createStore(t,i),o=i?.value,n.shouldPersist()){let c=await n.restore();o=c??o}e.addStore(i.name,n),o!==void 0&&(E("setting data to:",o),n.data=o)}static createStore(t,e){let s=t.createStore(e);return t.addStore(e.name,s),s}static async derealizeStore(t,e,s){E(`derealizeStore: derealizing "${s.name}"`),t.removeStore(s.name),e.removeStore(s.name)}static constructMeta(t,e,s){let o={...s,arcid:e.id,uid:t.uid};return{...o,owner:o.uid,shareid:`${o.name}:${o.arcid}:${o.uid}`}}};var Rt=a(a.flags.recipe,"ParticleCook","#5fa530"),$=class{static async execute(t,e,s){for(let o of s)await this.realizeParticle(t,e,o)}static async realizeParticle(t,e,s){Rt("realizedParticle:",s.id);let o=this.specToMeta(s.spec);return o.container||=s.container,t.bootstrapParticle(e,s.id,o)}static specToMeta(t){t.$bindings&&console.warn(`Particle '${t.$kind}' spec contains deprecated $bindings property (${JSON.stringify(t.$bindings)})`);let{$kind:e,$container:s,$staticInputs:o}=t,i=this.formatBindings(t.$inputs),n=this.formatBindings(t.$outputs);return{kind:e,staticInputs:o,inputs:i,outputs:n,container:s}}static formatBindings(t){return t?.map?.(e=>typeof e=="string"?{[e]:e}:e)}static async evacipate(t,e,s){return Promise.all(s.map(o=>this.derealizeParticle(t,e,o)))}static async derealizeParticle(t,e,s){e.removeHost(s.id)}};var x=a(a.flags.recipe,"Chef","#087f23"),at=class{static async execute(t,e,s){if(s instanceof Promise){x.error("`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.");return}x("|-->...| executing recipe: ",t);let o=new y(t);await u.execute(e,s,o.stores),await $.execute(e,s,o.particles),s.meta={...s.meta,...o.meta},x("|...-->| recipe complete: ",t.$meta??"")}static async evacipate(t,e,s){x("|-->...| evacipating recipe: ",t.$meta);let o=new y(t);await u.evacipate(e,s,o.stores),await $.evacipate(e,s,o.particles),x("|...-->| recipe evacipated: ",t.$meta)}static async executeAll(t,e,s){for(let o of t)await this.execute(o,e,s)}static async evacipateAll(t,e,s){for(let o of t)await this.evacipate(o,e,s)}};var pt={};_(pt,{fetchParticleCode:()=>ct,maybeFetchParticleCode:()=>lt,pathForKind:()=>ht,requireParticleBaseCode:()=>P,requireParticleImplCode:()=>Wt});var nt=class{map;constructor(r){this.map={},this.setRoot(r)}add(r){Object.assign(this.map,r||{})}resolve(r){let t;do r=this._resolve(t=r);while(t!==r);return r}_resolve(r){let t=r.split("/"),e=t.shift();return[this.map[e]||e,...t].join("/")}setRoot(r){r.length&&r[r.length-1]==="/"&&(r=r.slice(0,-1)),this.add({$root:r,$arcs:r})}getAbsoluteHereUrl(r,t){let e=r.url.split("/").slice(0,-(t??1)).join("/");if(globalThis?.document){let s=document.URL;s[s.length-1]!=="/"&&(s=`${s.split("/").slice(0,-1).join("/")}/`);let o=new URL(e,s).href;return o[o.length-1]==="/"&&(o=o.slice(0,-1)),o}else return e}},qt=import.meta.url.split("/").slice(0,-3).join("/"),S=globalThis.Paths=new nt(qt);S.add(globalThis.config?.paths);var R=a(a.flags.code,"code","gold","#333"),Kt="$arcs/core/Particle.js",Wt=async(r,t)=>{let e=t?.code||await ct(r);return e.slice(e.indexOf("({"))},ct=async r=>{if(r)return await lt(r);R.error("fetchParticleCode: empty 'kind'")},lt=async r=>{let t=ht(r);try{let e=await fetch(t);if(e.ok)return await e.text();throw""}catch{R.error(`could not locate implementation for particle "${r}" [${t}]`)}},ht=r=>r?(!"$./".includes(r[0])&&!r.includes("://")&&(r=`$library/${r}`),r?.split("/").pop().includes(".")||(r=`${r}.js`),S.resolve(r)):"404",P=async r=>{if(!P.source){let t=S.resolve(r||Kt);R("particle base code path: ",t);let s=await(await fetch(t)).text()+` //# sourceURL=`+t+` `;P.source=s.replace(/export /g,"")}return P.source};P.source=null;var q={};_(q,{PathMapper:()=>nt,Paths:()=>S,arand:()=>z,async:()=>Vt,asyncTask:()=>Gt,computeAgeString:()=>_t,debounce:()=>Jt,deepCopy:()=>h,deepEqual:()=>f,deepUndefinedToNull:()=>Y,irand:()=>O,key:()=>xt,logFactory:()=>a,makeId:()=>g,matches:()=>U,prob:()=>St,shallowMerge:()=>yt,shallowUpdate:()=>mt});var _t=(r,t)=>{let e=Math.round((t-r)/1e3);if(isNaN(e))return"\u2022";let s="";return e<60?(e>1&&(s="s"),`${e} second${s} ago`):(e=Math.round(e/60),e<60?(e>1&&(s="s"),`${e} minute${s} ago`):(e=Math.round(e/60),e<24?(e>1&&(s="s"),`${e} hour${s} ago`):(e=Math.round(e/24),e<30?(e>1&&(s="s"),`${e} day${s} ago`):(e=Math.round(e/30),e<12?(e>1&&(s="s"),`${e} month${s} ago`):(e=Math.round(e/12),e>1&&(s="s"),`${e} year${s} ago`)))))};var Jt=(r,t,e)=>{if(r&&clearTimeout(r),t&&e)return setTimeout(t,e)},Vt=r=>async(...t)=>{await Promise.resolve(),r(...t)},Gt=(r,t)=>{setTimeout(r,t??0)};var{logFactory:ts,Paths:Qt}=q;var Xt=import.meta.url.split("/").slice(0,-1).join("/");Qt.setRoot(Xt);export{w as Arc,at as Chef,M as DataStore,L as Decorator,l as EventEmitter,d as Host,y as Parser,$ as ParticleCook,Qt as Paths,m as Runtime,j as Store,u as StoreCook,pt as code,ts as logFactory,q as utils}; /** diff --git a/pkg/Library/Core/arcs.min.js.map b/pkg/Library/Core/arcs.min.js.map index eb9129b8..b70cb40b 100644 --- a/pkg/Library/Core/arcs.min.js.map +++ b/pkg/Library/Core/arcs.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../../core/js/core/EventEmitter.js", "../../../core/js/utils/types.js", "../../../core/js/utils/log.js", "../../../core/js/core/Arc.js", "../../../core/js/utils/object.js", "../../../core/js/utils/rand.js", "../../../core/js/core/Decorator.js", "../../../core/js/core/Host.js", "../../../core/js/core/Store.js", "../../../core/js/utils/id.js", "../../../core/js/Runtime.js", "../../../core/js/recipe/RecipeParser.js", "../../../core/js/utils/matching.js", "../../../core/js/recipe/StoreCook.js", "../../../core/js/recipe/ParticleCook.js", "../../../core/js/recipe/Chef.js", "../../../core/js/isolation/code.js", "../../../core/js/utils/paths.js", "../../../core/js/utils/utils.js", "../../../core/js/utils/date.js", "../../../core/js/utils/task.js", "../../../core/src/arcs.ts"], - "sourcesContent": ["/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport class EventEmitter {\n // map of event name to listener array\n listeners = {};\n getEventListeners(eventName) {\n return this.listeners[eventName] || (this.listeners[eventName] = []);\n }\n fire(eventName, ...args) {\n const listeners = this.getEventListeners(eventName);\n if (listeners?.forEach) {\n listeners.forEach(listener => listener(...args));\n }\n }\n listen(eventName, listener, listenerName) {\n const listeners = this.getEventListeners(eventName);\n listeners.push(listener);\n listener._name = listenerName || '(unnamed listener)';\n return listener;\n }\n unlisten(eventName, listener) {\n const list = this.getEventListeners(eventName);\n const index = (typeof listener === 'string') ? list.findIndex(l => l._name === listener) : list.indexOf(listener);\n if (index >= 0) {\n list.splice(index, 1);\n }\n else {\n console.warn('failed to unlisten from', eventName);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const logKinds = ['log', 'group', 'groupCollapsed', 'groupEnd', 'dir'];\nexport const errKinds = ['warn', 'error'];\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logKinds, errKinds } from './types.js';\nconst { fromEntries } = Object;\nconst _logFactory = (enable, preamble, bg, color, kind = 'log') => {\n if (typeof enable === 'string') {\n enable = logFactory.flags[enable];\n }\n if (!enable) {\n return () => { };\n }\n if (kind === 'dir') {\n return console.dir.bind(console);\n }\n const style = `background: ${bg || 'gray'}; color: ${color || 'white'}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;\n return console[kind].bind(console, `%c${preamble}`, style);\n};\nexport const logFactory = (enable, preamble, bg = '', color = '') => {\n const debugLoggers = fromEntries(logKinds.map(kind => [kind, _logFactory(enable, preamble, bg, color, kind)]));\n const errorLoggers = fromEntries(errKinds.map(kind => [kind, _logFactory(true, preamble, bg, color, kind)]));\n const loggers = { ...debugLoggers, ...errorLoggers };\n // Inject `log` as default, keeping all loggers available to be invoked by name.\n const log = loggers.log;\n Object.assign(log, loggers);\n return log;\n};\nlogFactory.flags = globalThis.config?.logFlags || {};\n", "/**\n * @license\n * Copyright (c) 2022 Google LLC All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\nimport { EventEmitter } from './EventEmitter.js';\nimport { logFactory } from '../utils/log.js';\nconst customLogFactory = (id) => logFactory(logFactory.flags.arc, `Arc (${id})`, 'slateblue');\nconst { assign, create } = Object;\nconst entries = (o) => Object.entries(o ?? Object);\nconst keys = (o) => Object.keys(o ?? Object);\nconst values = (o) => Object.values(o ?? Object);\nconst nob = () => create(null);\nexport class Arc extends EventEmitter {\n log;\n id;\n meta;\n stores;\n hosts;\n surface;\n composer;\n hostService;\n constructor(id, meta, surface) {\n super();\n this.id = id;\n this.meta = meta;\n this.surface = surface;\n this.hosts = nob();\n this.stores = nob();\n this.log = customLogFactory(id);\n }\n async addHost(host, surface) {\n // to support hosts we need a composer\n await this.ensureComposer();\n // bookkeep\n this.hosts[host.id] = host;\n host.arc = this;\n // TODO(sjmiles): support per host surfacing?\n //await host.bindToSurface(surface ?? this.surface);\n // begin work\n this.updateHost(host);\n return host;\n }\n async ensureComposer() {\n if (!this.composer && this.surface) {\n // create composer\n this.composer = await this.surface.createComposer('root');\n // pipeline for events from composer to this.onevent\n // TODO(sjmiles): use 'bind' to avoid a closure and improve the stack trace\n this.composer.onevent = this.onevent.bind(this);\n }\n }\n rerender() {\n values(this.hosts).forEach(h => h.rerender());\n }\n removeHost(id) {\n this.hosts[id]?.detach();\n delete this.hosts[id];\n }\n addStore(storeId, store) {\n if (store && !this.stores[storeId]) {\n this.stores[storeId] = store;\n store.listen('change', () => this.storeChanged(storeId, store), this.id);\n }\n }\n removeStore(storeId) {\n const store = this.stores[storeId];\n if (store) {\n store.unlisten('change', this.id);\n }\n delete this.stores[storeId];\n }\n // TODO(sjmiles): 2nd param is used in overrides, make explicit\n storeChanged(storeId, store) {\n this.log(`storeChanged: \"${storeId}\"`);\n const isBound = inputs => inputs && inputs.some(input => input && (values(input)[0] == storeId || keys(input)[0] == storeId));\n values(this.hosts).forEach(host => {\n const inputs = host.meta?.inputs;\n if (inputs === '*' || isBound(inputs)) {\n this.log(`host \"${host.id}\" has interest in \"${storeId}\"`);\n // TODO(sjmiles): we only have to update inputs for storeId, we lose efficiency here\n this.updateHost(host);\n }\n });\n this.fire('store-changed', storeId);\n }\n updateParticleMeta(hostId, meta) {\n const host = this.hosts[hostId];\n host.meta = meta;\n this.updateHost(host);\n }\n updateHost(host) {\n host.inputs = this.computeInputs(host);\n }\n // TODO(sjmiles): debounce? (update is sync-debounced already)\n // complement to `assignOutputs`\n computeInputs(host) {\n const inputs = nob();\n const inputBindings = host.meta?.inputs;\n if (inputBindings === '*') {\n // TODO(sjmiles): we could make the contract that the bindAll inputs are\n // names (or names + meta) only. The Particle could look up values via\n // service (to reduce throughput requirements)\n entries(this.stores).forEach(([name, store]) => inputs[name] = store.pojo);\n }\n else {\n const staticInputs = host.meta?.staticInputs;\n assign(inputs, staticInputs);\n if (inputBindings) {\n inputBindings.forEach(input => input && this.computeInput(entries(input)[0], inputs));\n this.log(`computeInputs(${host.id}) =`, inputs);\n }\n }\n return inputs;\n }\n computeInput([name, binding], inputs) {\n const storeName = binding || name;\n const store = this.stores[storeName];\n if (store) {\n inputs[name] = store.pojo;\n }\n else {\n // TODO(sjmiles): is this ok or not?\n //this.log.warn(`computeInput: \"${storeName}\" (bound to \"${name}\") not found`);\n }\n }\n // complement to `computeInputs`\n assignOutputs({ id, meta }, outputs) {\n const names = keys(outputs);\n if (meta?.outputs && names.length) {\n names.forEach(name => this.assignOutput(name, outputs[name], meta.outputs));\n this.log(`[end][${id}] assignOutputs:`, outputs);\n }\n }\n assignOutput(name, output, outputs) {\n if (output !== undefined) {\n const binding = this.findOutputByName(outputs, name) || name;\n const store = this.stores[binding];\n if (!store) {\n if (outputs?.[name]) {\n this.log.warn(`assignOutputs: no \"${binding}\" store for output \"${name}\"`);\n }\n }\n else {\n // Note: users can mess up output data in any way they see fit, so we should\n // probably invent `outputCleansing`.\n this.log(`assignOutputs: \"${name}\" is dirty, updating Store \"${binding}\"`, output);\n store.data = output;\n }\n }\n }\n findOutputByName(outputs, name) {\n const output = outputs?.find(output => keys(output || 0)[0] === name);\n if (output) {\n return values(output)[0];\n }\n }\n async render(packet) {\n if (this.composer) {\n this.composer.render({ ...packet, arcid: this.id });\n }\n else {\n //this.log.low('render called, but composer is null', packet);\n }\n }\n onevent(pid, eventlet) {\n const host = this.hosts[pid];\n if (host) {\n host.handleEvent(eventlet);\n }\n }\n async service(host, request) {\n let result = await this.surface?.service(request);\n if (result === undefined) {\n result = this.hostService?.(host, request);\n }\n return result;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/*\n * update the fields of `obj` with the fields of `data`,\n * perturbing `obj` as little as possible (since it might be a magic proxy thing\n * like an Automerge document)\n */\nexport const shallowUpdate = (obj, data) => {\n let result = data;\n if (!data) {\n //\n }\n else if (Array.isArray(data)) {\n if (!Array.isArray(obj)) {\n // TODO(sjmiles): eek, very perturbing to obj\n obj = [];\n }\n for (let i = 0; i < data.length; i++) {\n const value = data[i];\n if (obj[i] !== value) {\n obj[i] = value;\n }\n }\n const overage = obj.length - data.length;\n if (overage > 0) {\n obj.splice(data.length, overage);\n }\n }\n else if (typeof data === 'object') {\n result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n const seen = {};\n // for each key in input data ...\n Object.keys(data).forEach(key => {\n // copy that data into output\n result[key] = data[key];\n // remember the key\n seen[key] = true;\n });\n // for each key in the output data...\n Object.keys(result).forEach(key => {\n // if this key was not in the input, remove it\n if (!seen[key]) {\n delete result[key];\n }\n });\n }\n return result;\n};\nexport const shallowMerge = (obj, data) => {\n if (data == null) {\n return null;\n }\n if (typeof data === 'object') {\n const result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n Object.keys(data).forEach(key => result[key] = data[key]);\n return result;\n }\n return data;\n};\nexport function deepCopy(datum) {\n if (!datum) {\n return datum;\n }\n else if (Array.isArray(datum)) {\n // This is trivially type safe but tsc needs help\n return datum.map(element => deepCopy(element));\n }\n else if (typeof datum === 'object') {\n const clone = Object.create(null);\n Object.entries(datum).forEach(([key, value]) => {\n clone[key] = deepCopy(value);\n });\n return clone;\n }\n else {\n return datum;\n }\n}\nexport const deepEqual = (a, b) => {\n const type = typeof a;\n // must be same type to be equal\n if (type !== typeof b) {\n return false;\n }\n // we are `deep` because we recursively study object types\n if (type === 'object' && a && b) {\n const aProps = Object.getOwnPropertyNames(a);\n const bProps = Object.getOwnPropertyNames(b);\n // equal if same # of props, and no prop is not deepEqual\n return (aProps.length == bProps.length) && !aProps.some(name => !deepEqual(a[name], b[name]));\n }\n // finally, perform simple comparison\n return (a === b);\n};\nexport const deepUndefinedToNull = (obj) => {\n if (obj === undefined) {\n return null;\n }\n if (obj && (typeof obj === 'object')) {\n // we are `deep` because we recursively study object types\n const props = Object.getOwnPropertyNames(obj);\n props.forEach(name => {\n const prop = obj[name];\n if (prop === undefined) {\n delete obj[name];\n //obj[name] = null;\n }\n else {\n deepUndefinedToNull(prop);\n }\n });\n }\n return obj;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nconst { floor, pow, random } = Math;\n// random n-digit number\nexport const key = (digits) => floor((1 + random() * 9) * pow(10, digits - 1));\n// random integer from [0..range)\nexport const irand = (range) => floor(random() * range);\n// random element from array\nexport const arand = (array) => array[irand(array.length)];\n// test if event has occured, where `probability` is between [0..1]\nexport const prob = (probability) => Boolean(random() < probability);\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepCopy } from '../utils/object.js';\nconst log = logFactory(logFactory.flags.decorator, 'Decorator', 'plum');\nconst { values, entries } = Object;\nconst opaqueData = {};\nexport const Decorator = {\n setOpaqueData(name, data) {\n opaqueData[name] = data; //deepCopy(data);\n return name;\n },\n getOpaqueData(name) {\n return opaqueData[name];\n },\n maybeDecorateModel(model, particle) {\n if (model && !Array.isArray(model)) {\n // for each item in model, regardless of key\n values(model).forEach((item) => {\n // is an object?\n if (item && (typeof item === 'object')) {\n // are there sub-models\n if (item['models']) {\n // the decorate this item\n log('applying decorator(s) to list:', item);\n this.maybeDecorateItem(item, particle);\n }\n else {\n // otherwise, check if there are sub-items to decorate\n if (model?.filter || model?.decorator || model?.collateBy) {\n log('scanning for lists in sub-model:', item);\n this.maybeDecorateModel(item, particle);\n }\n }\n }\n });\n }\n // possibly decorated model\n return model;\n },\n maybeDecorateItem(item, particle) {\n let models = (typeof item.models === 'string') ? this.getOpaqueData(item.models) : item.models;\n if (models) {\n // do a decorator\n models = maybeDecorate(models, item.decorator, particle);\n // do a filter\n models = maybeFilter(models, item.filter, particle.impl);\n // do a collator\n models = maybeCollateBy(models, item);\n // mutate items\n item.models = models;\n //console.log(JSON.stringify(models, null, ' '));\n }\n },\n};\nconst maybeDecorate = (models, decorator, particle) => {\n decorator = particle.impl[decorator] ?? decorator;\n const { inputs, state } = particle.internal;\n if (decorator) {\n // TODO(cromwellian): Could be expensive to do everything, store responsibility?\n const immutableInputs = Object.freeze(deepCopy(inputs));\n // we don't want the decorator to have access to mutable globals\n const immutableState = Object.freeze(deepCopy(state));\n // models become decorous\n models = models.map(model => {\n // use previously mutated data or initialize\n // TODO(cromwellian): I'd like to do Object.freeze() here, also somehow not mutate the models inplace\n // Possibly have setOpaqueData wrap the data so the privateData lives on the wrapper + internal immutable data\n model.privateData = model.privateData || {};\n // TODO(cromwellian): also could be done once during setOpaqueData() if we can track privateData differently\n const immutableModel = Object.freeze(deepCopy(model));\n const decorated = decorator(immutableModel, immutableInputs, immutableState);\n // set new privateData from returned\n model.privateData = decorated.privateData;\n return { ...decorated, ...model, };\n });\n // sort (possible that all values undefined)\n models.sort(sortByLc('sortKey'));\n log('decoration was performed');\n }\n //models.forEach(model => delete model.privateData);\n return models;\n};\nconst maybeFilter = (models, filter, impl) => {\n filter = impl[filter] ?? filter;\n if (filter && models) {\n // models become filtrated\n models = models.filter(filter);\n }\n return models;\n};\nconst maybeCollateBy = (models, item) => {\n // construct requested sub-lists\n entries(item).forEach(([name, collator]) => {\n // generate named collations for items of the form `[name]: {collateBy}`\n if (collator?.['collateBy']) {\n // group the models into buckets based on the model-field named by `collateBy`\n const collation = collate(models, collator['collateBy']);\n models = collationToRenderModels(collation, name, collator['$template']);\n }\n });\n return models;\n};\nconst sortByLc = key => (a, b) => sort(String(a[key]).toLowerCase(), String(b[key]).toLowerCase());\n//const sortBy = key => (a, b) => sort(a[key], b[key]);\nconst sort = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst collate = (models, collateBy) => {\n const collation = {};\n models.forEach(model => {\n const keyValue = model[collateBy];\n if (keyValue) {\n const category = collation[keyValue] || (collation[keyValue] = []);\n category.push(model);\n }\n });\n return collation;\n};\nconst collationToRenderModels = (collation, name, $template) => {\n return entries(collation).map(([key, models]) => ({\n key,\n [name]: { models, $template },\n single: !(models['length'] !== 1),\n ...models?.[0]\n }));\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepEqual, deepCopy } from '../utils/object.js';\nimport { arand } from '../utils/rand.js';\nimport { EventEmitter } from './EventEmitter.js';\nimport { Decorator } from './Decorator.js';\nconst { entries, keys } = Object;\nconst customLogFactory = (id) => logFactory(logFactory.flags.host, `Host (${id})`, arand(['#5a189a', '#51168b', '#48137b', '#6b2fa4', '#7b46ae', '#3f116c']));\n/**\n * Host owns metadata (e.g. `id`, `container`) that its Particle is not allowed to access.\n * Host knows how to talk, asynchronously, to its Particle (potentially using a bus).\n**/\n/* TODO(sjmiles):\nUpdate Cycle Documented Briefly\n1. when a Store changes it invokes it's listeners\n2. when an Arc hears a Store change, it updates Hosts bound to the Store\n3. Arc updates Host by creating an `inputs` object from Stores and metadata\n - ignores fact inputs are accumulated\n - ignores information about which Store has updated\n4. `inputs` object is assigned to `hosts.inputs` \uD83D\uDE43\n5. Host does an expensive `deepEqual` equality check. Turning on `host` logging should reveal `this.log('inputs are not interesting, skipping update');` if data is caught in this trap\n - we can use reference testing here if we are more careful\n about using immutable data\n6. the particle.inputs are assigned (but is really a *merge*)\n*/\nexport class Host extends EventEmitter {\n arc;\n id;\n lastOutput;\n lastPacket;\n lastRenderModel;\n log;\n meta;\n particle;\n constructor(id) {\n super();\n this.log = customLogFactory(id);\n this.id = id;\n }\n onevent(eventlet) {\n this.arc?.onevent(eventlet);\n this.fire('eventlet', eventlet);\n }\n // Particle and ParticleMeta are separate, host specifically integrates these on behalf of Particle\n installParticle(particle, meta) {\n if (this.particle) {\n this.detachParticle();\n }\n if (particle) {\n this.particle = particle;\n this.meta = meta || this.meta;\n }\n }\n get container() {\n return this.meta?.container || 'root';\n }\n detach() {\n this.detachParticle();\n this.arc = null;\n }\n detachParticle() {\n if (this.particle) {\n this.render({ $clear: true });\n this.particle = null;\n this.meta = null;\n }\n }\n async service(request) {\n if (request?.decorate) {\n return Decorator.maybeDecorateModel(request.model, this.particle);\n }\n return this.arc?.service(this, request);\n }\n output(outputModel, renderModel) {\n if (outputModel) {\n this.lastOutput = outputModel;\n this.arc?.assignOutputs(this, outputModel);\n this.fire('output', outputModel);\n }\n if (this.template) {\n Decorator.maybeDecorateModel(renderModel, this.particle);\n this.lastRenderModel = { ...renderModel };\n this.render(renderModel);\n }\n }\n rerender() {\n // does not re-render Frame/Slot content\n // you probably want Arc::rerender\n if (this.lastRenderModel) {\n this.render(this.lastRenderModel);\n }\n }\n render(model) {\n const { id, container, template } = this;\n const content = { model, template };\n const packet = { id, container, content };\n this.fire('render', packet);\n this.arc?.render(packet);\n this.lastPacket = packet;\n }\n set inputs(inputs) {\n if (this.particle && inputs) {\n const lastInputs = this.particle.internal.inputs;\n if (this.dirtyCheck(inputs, lastInputs, this.lastOutput)) {\n this.particle.inputs = deepCopy({ ...this.meta?.staticInputs, ...inputs });\n this.fire('inputs-changed');\n }\n else {\n this.log('inputs are uninteresting, skipping update');\n }\n }\n }\n dirtyCheck(inputs, lastInputs, lastOutput) {\n const dirtyBits = ([n, v]) => (lastOutput?.[n] && !deepEqual(lastOutput[n], v))\n || !deepEqual(lastInputs?.[n], v);\n return !lastInputs\n || entries(inputs).length !== this.lastInputsLength(lastInputs)\n || entries(inputs).some(dirtyBits);\n }\n lastInputsLength(lastInputs) {\n return keys(lastInputs).filter(key => !this.meta?.staticInputs?.[key] && key !== 'eventlet').length;\n }\n get config() {\n return this.particle?.config;\n }\n get template() {\n return this.config?.template;\n }\n invalidate() {\n this.particle?.invalidate();\n }\n handleEvent(eventlet) {\n return this.particle?.handleEvent(eventlet);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { EventEmitter } from './EventEmitter.js';\nconst { create, keys } = Object;\nconst { stringify, parse } = JSON;\nexport class DataStore extends EventEmitter {\n privateData;\n constructor() {\n super();\n }\n setPrivateData(data) {\n this.privateData = data;\n }\n set data(data) {\n this.setPrivateData(data);\n }\n get data() {\n return this.privateData;\n }\n toString() {\n return this.pretty;\n }\n get isObject() {\n return this.data && typeof this.data === 'object';\n }\n get pojo() {\n return this.data;\n }\n get json() {\n return stringify(this.data);\n }\n set json(json) {\n let value = null;\n try {\n value = parse(json);\n }\n catch (x) {\n //\n }\n this.data = value;\n }\n get pretty() {\n const sorted = {};\n const pojo = this.pojo;\n keys(pojo).sort().forEach(key => sorted[key] = pojo[key]);\n return stringify(sorted, null, ' ');\n }\n}\nclass ObservableStore extends DataStore {\n change(mutator) {\n mutator(this);\n this.doChange();\n }\n doChange() {\n this.fire('change', this);\n this.onChange(this);\n }\n onChange(store) {\n // override\n }\n set data(data) {\n this.change(self => self.setPrivateData(data));\n }\n // TODO(sjmiles): one of the compile/build/bundle tools\n // evacipates the inherited getter, so we clone it\n get data() {\n return this['privateData'];\n }\n set(key, value) {\n if (!this.data) {\n this.setPrivateData(create(null));\n }\n if (value !== undefined) {\n this.change(self => self.data[key] = value);\n }\n else {\n this.delete(key);\n }\n }\n delete(key) {\n this.change(doc => delete doc.data[key]);\n }\n}\nclass PersistableStore extends ObservableStore {\n meta;\n constructor(meta) {\n super();\n this.meta = { ...meta };\n }\n toString() {\n return `${JSON.stringify(this.meta, null, ' ')}, ${this.pretty}`;\n }\n get tags() {\n return this.meta.tags ?? (this.meta.tags = []);\n }\n is(...tags) {\n // true if every member of `tags` is also in `this.tags`\n return tags.every(tag => this.tags.includes(tag));\n }\n isCollection() {\n return this.meta.type?.[0] === '[';\n }\n shouldPersist() {\n return this.is('persisted') && !this.is('volatile');\n }\n async doChange() {\n // do not await\n this.persist();\n return super.doChange();\n }\n // TODO(sjmiles): as of now the persist/restore methods\n // are bound in Runtime:addStore\n async persist() {\n }\n async restore( /*value: any*/) {\n }\n // delete() {\n // this.persistor?.remove(this);\n // }\n save() {\n return this.json;\n }\n load(serial, defaultValue) {\n let value = defaultValue;\n try {\n if (serial) {\n value = parse(serial);\n }\n }\n catch (x) {\n //\n }\n if (value !== undefined) {\n this.data = value;\n }\n }\n}\nexport class Store extends PersistableStore {\n}\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { irand } from \"./rand.js\";\nexport const makeId = (pairs, digits, delim) => {\n pairs = pairs || 2;\n digits = digits || 2;\n delim = delim || '-';\n const min = Math.pow(10, digits - 1);\n const range = Math.pow(10, digits) - min;\n const result = [];\n for (let i = 0; i < pairs; i++) {\n result.push(`${irand(range - min) + min}`);\n }\n return result.join(delim);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Arc } from './core/Arc.js';\nimport { Host } from './core/Host.js';\nimport { Store } from './core/Store.js';\nimport { EventEmitter } from './core/EventEmitter.js';\nimport { logFactory } from './utils/log.js';\nimport { makeId } from './utils/id.js';\nconst log = logFactory(logFactory.flags.runtime, 'runtime', '#873600');\nconst particleFactoryCache = {};\nconst storeFactories = {};\nconst { keys } = Object;\nexport class Runtime extends EventEmitter {\n log;\n uid; // user id\n nid; // network id\n arcs;\n stores;\n peers;\n shares;\n endpoint;\n network;\n surfaces;\n persistor;\n prettyUid;\n static securityLockdown;\n static particleIndustry;\n static particleOptions;\n constructor(uid) {\n uid = uid || 'user';\n super();\n this.arcs = {};\n this.surfaces = {};\n this.stores = {};\n this.peers = new Set();\n this.shares = new Set();\n this.setUid(uid);\n this.log = logFactory(logFactory.flags.runtime, `runtime:[${this.prettyUid}]`, '#873600');\n //Runtime.securityLockdown?.(Runtime.particleOptions);\n }\n setUid(uid) {\n this.uid = uid;\n this.nid = `${uid}:${makeId(1, 2)}`;\n this.prettyUid = uid.substring(0, uid.indexOf('@') + 1) || uid;\n }\n async bootstrapArc(name, meta, surface, service) {\n // make an arc on `surface`\n const arc = new Arc(name, meta, surface);\n // install service handler\n arc.hostService = this.serviceFactory(service);\n // add `arc` to runtime\n await this.addArc(arc);\n // fin\n return arc;\n }\n serviceFactory(service) {\n return async (host, request) => service.handle(this, host, request);\n }\n // TODO(sjmiles): duplication vis a vis `installParticle`\n // used by? ... [ParticleCook.js]\n async bootstrapParticle(arc, id, meta) {\n // make a host\n const host = new Host(id);\n // make a particle\n await this.marshalParticle(host, meta);\n // add `host` to `arc`\n await arc.addHost(host);\n // report\n log('bootstrapped particle', id);\n //log(host);\n return host;\n }\n // no-op surface mapping\n addSurface(id, surface) {\n this.surfaces[id] = surface;\n }\n getSurface(id) {\n return this.surfaces[id];\n }\n // map arcs by arc.id\n addArc(arc) {\n const { id } = arc;\n if (id && !this.arcs[id]) {\n return this.arcs[id] = arc;\n }\n throw `arc has no id, or id \"${id}\" is already in use`;\n }\n removeArc(arc) {\n const { id } = arc;\n if (!id || !this.arcs[id]) {\n throw !id ? `arc has no id` : `id \"${id}\" is not in use`;\n }\n delete this.arcs[id];\n }\n // create a particle inside of host\n async marshalParticle(host, particleMeta) {\n const particle = await this.createParticle(host, particleMeta.kind);\n return host.installParticle(particle, particleMeta);\n }\n // create a host, install a particle, add host to arc\n // TODO(sjmiles): duplication vis a vis `bootstrapParticle`\n // used by? ... [ArcsWorker.js]\n async installParticle(arc, particleMeta, name) {\n this.log('installParticle', name, particleMeta, arc.id);\n // provide a default name\n name = name || makeId();\n // deduplicate name\n if (arc.hosts[name]) {\n let n = 1;\n for (; (arc.hosts[`${name}-${n}`]); n++)\n ;\n name = `${name}-${n}`;\n }\n // build the structure\n const host = new Host(name);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n }\n // TODO(sjmiles): third version to rule them all; bring your own host\n async addParticle(arc, host, particleMeta, name) {\n this.log('addParticle', arc.id, name, particleMeta, arc.id);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n // this.log('addParticle', name, particleMeta, arc.id);\n // // provide a default name\n // name = name || makeId();\n // // deduplicate name\n // if (arc.hosts[name]) {\n // let n = 1;\n // for (; (arc.hosts[`${name}-${n}`]); n++);\n // name = `${name}-${n}`;\n // }\n // // build the structure\n // const host = new Host(name);\n // await this.marshalParticle(host, particleMeta);\n // await arc.addHost(host);\n // return host;\n }\n idFromName(name, list) {\n // provide a default name\n let id = name || makeId();\n // deduplicate name\n if (list[id]) {\n let n = 1;\n for (; (list[`${id}-${n}`]); n++)\n ;\n id = `${id}-${n}`;\n }\n // return unique id\n return id;\n }\n // map a store by a Runtime-specific storeId\n // Stores have no intrinsic id\n addStore(storeId, store) {\n // if the store needs to discuss things with Runtime\n // TODO(sjmiles): this is likely unsafe for re-entry\n if (store.marshal) {\n store.marshal(this);\n }\n // bind to persist/restore functions\n store.persist = async () => this.persistStore(storeId, store);\n store.restore = async () => this.restoreStore(storeId, store);\n // override the Store's own persistor to use the runtime persistor\n // TODO(sjmiles): why?\n // if (store.persistor) {\n // store.persistor.persist = store => this.persistor?.persist(storeId, store);\n // }\n // bind this.storeChanged to store.change (and name the binding)\n const name = `${this.nid}:${storeId}-changed`;\n const onChange = this.storeChanged.bind(this, storeId);\n store.listen('change', onChange, name);\n // map the store\n this.stores[storeId] = store;\n // evaluate for sharing\n this.maybeShareStore(storeId);\n // notify listeners that a thing happened\n // TODO(sjmiles): makes no sense without id\n //this.fire('store-added', store);\n }\n async persistStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`persistStore \"${storeId}\"`);\n return this.persistor?.persist?.(storeId, store.data);\n }\n }\n async restoreStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`restoreStore \"${storeId}\"`);\n return this.persistor?.restore?.(storeId);\n }\n }\n storeChanged(storeId, store) {\n this.log('storeChanged', storeId);\n this.network?.invalidatePeers(storeId);\n this.onStoreChange(storeId, store);\n this.fire('store-changed', { storeId, store });\n }\n // TODO(sjmiles): evacipate this method\n onStoreChange(storeId, store) {\n // override for bespoke response\n }\n do(storeId, task) {\n task(this.stores[storeId]);\n }\n removeStore(storeId) {\n this.do(storeId, store => {\n store?.unlisten('change', `${this.nid}:${storeId}-changed`);\n });\n delete this.stores[storeId];\n }\n maybeShareStore(storeId) {\n this.do(storeId, store => {\n if (store?.is('shared')) {\n this.shareStore(storeId);\n }\n });\n }\n addPeer(peerId) {\n this.peers.add(peerId);\n [...this.shares].forEach(storeId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n shareStore(storeId) {\n this.shares.add(storeId);\n [...this.peers].forEach(peerId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n maybeShareStoreWithPeer(storeId, peerId) {\n this.do(storeId, store => {\n const nid = this.uid.replace(/\\./g, '_');\n if (!store.is('private') || (peerId.startsWith(nid))) {\n this.shareStoreWithPeer(storeId, peerId);\n }\n });\n }\n shareStoreWithPeer(storeId, peerId) {\n this.network?.shareStore(storeId, peerId);\n }\n async createParticle(host, kind) {\n try {\n const factory = await this.marshalParticleFactory(kind);\n return factory?.(host);\n }\n catch (x) {\n log.error(`createParticle(${kind}):`, x);\n }\n }\n async marshalParticleFactory(kind) {\n return particleFactoryCache[kind] ?? this.lateBindParticle(kind);\n }\n lateBindParticle(kind, code) {\n const { particleOptions, particleIndustry, registerFactoryPromise } = Runtime;\n if (!particleIndustry) {\n throw `no ParticleIndustry to create '${kind}'`;\n }\n else {\n const factoryPromise = particleIndustry(kind, { ...particleOptions, code });\n registerFactoryPromise(kind, factoryPromise);\n return factoryPromise;\n }\n }\n static registerFactoryPromise(kind, factoryPromise) {\n return particleFactoryCache[kind] = factoryPromise;\n }\n requireStore(meta) {\n let store = this.stores[meta.name];\n if (!store) {\n store = this.createStore(meta);\n this.addStore(meta.name, store);\n }\n return store;\n }\n createStore(meta) {\n const key = keys(storeFactories).find(tag => meta.tags?.includes?.(tag));\n const storeClass = storeFactories[String(key)] || Store;\n return new storeClass(meta);\n }\n static registerStoreClass(tag, storeClass) {\n storeFactories[tag] = storeClass;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'RecipeParser', 'violet');\nconst { entries, create } = Object;\nexport class Parser {\n stores;\n particles;\n slots;\n meta;\n constructor(recipe) {\n this.stores = [];\n this.particles = [];\n this.slots = [];\n this.meta = create(null);\n if (recipe) {\n this.parse(recipe);\n }\n }\n parse(recipe) {\n // `normalize` converts shorthand to longhand before parsing\n const normalized = this.normalize(recipe);\n this.parseSlotSpec(normalized, 'root', '');\n return this;\n }\n normalize(recipe) {\n if (typeof recipe !== 'object') {\n throw Error('recipe must be an Object');\n }\n // TODO(sjmiles): would be great if `normalize` normalized all the things\n return recipe;\n }\n parseSlotSpec(spec, slotName, parentName) {\n // process entries\n for (const key in spec) {\n switch (key) {\n case '$meta':\n // value is a dictionary\n this.meta = { ...this.meta, ...spec.$meta };\n break;\n case '$stores':\n // value is a StoreSpec\n this.parseStoresNode(spec.$stores);\n break;\n default: {\n // value is a ParticleSpec\n const container = parentName ? `${parentName}#${slotName}` : slotName;\n this.parseParticleSpec(container, key, spec[key]);\n break;\n }\n }\n }\n }\n parseStoresNode(stores) {\n for (const key in stores) {\n this.parseStoreSpec(key, stores[key]);\n }\n }\n parseStoreSpec(name, spec) {\n if (this.stores.find(s => s.name === name)) {\n log('duplicate store name');\n return;\n }\n const meta = {\n name,\n type: spec.$type,\n tags: spec.$tags,\n value: spec.$value\n };\n this.stores.push(meta);\n }\n parseParticleSpec(container, id, spec) {\n if (!spec.$kind) {\n log.warn(`parseParticleSpec: malformed spec has no \"kind\":`, spec);\n throw Error();\n }\n if (this.particles.find(s => s.id === id)) {\n log('duplicate particle name', id, spec);\n return;\n }\n this.particles.push({ id, container, spec });\n if (spec.$slots) {\n this.parseSlotsNode(spec.$slots, id);\n }\n }\n parseSlotsNode(slots, parent) {\n entries(slots).forEach(([key, spec]) => this.parseSlotSpec(spec, key, parent));\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport function matches(candidateMeta, targetMeta) {\n for (const property in targetMeta) {\n if (candidateMeta[property] !== targetMeta[property]) {\n return false;\n }\n }\n return true;\n}\n;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { matches } from '../utils/matching.js';\nconst log = logFactory(logFactory.flags.recipe, 'StoreCook', '#99bb15');\nconst { values } = Object;\nconst mapStore = (runtime, { name, type }) => {\n return findStores(runtime, { name, type })?.[0];\n};\nconst findStores = (runtime, criteria) => {\n return values(runtime.stores).filter(store => storeMatches(store, criteria));\n};\nconst storeMatches = (store, criteria) => {\n // TODO(b/244191110): Type matching API to be wired here.\n const { type, ...other } = criteria;\n if (typeMatches(type, store?.meta.type)) {\n // generic object comparison\n return matches(store?.meta, other);\n }\n};\nconst typeMatches = (typeA, typeB) => {\n const baseTypes = ['pojo', 'json'];\n return (typeA === typeB)\n || baseTypes.includes(typeA?.toLowerCase())\n || baseTypes.includes(typeB?.toLowerCase());\n};\nexport class StoreCook {\n static async execute(runtime, arc, stores) {\n return this.forEachStore(this.realizeStore, runtime, arc, stores);\n }\n static async evacipate(runtime, arc, stores) {\n return this.forEachStore(this.derealizeStore, runtime, arc, stores);\n }\n static async forEachStore(task, runtime, arc, stores) {\n return Promise.all(stores.map(store => task.call(this, runtime, arc, store)));\n }\n static async realizeStore(runtime, arc, rawMeta) {\n // potential initialization value\n let value;\n // build a StoreMeta out of parts\n const meta = this.constructMeta(runtime, arc, rawMeta);\n // do we already own this Store?\n let store = mapStore(runtime, meta);\n if (store) {\n // use a Store\n log(`realizeStore: mapping \"${rawMeta.name}\" to \"${store.meta.name}\"`);\n }\n else {\n log(`realizeStore: creating \"${meta.name}\"`);\n // create a Store\n store = StoreCook.createStore(runtime, meta);\n // default initial value comes from meta\n value = meta?.value;\n // persisted value may override default\n if (store.shouldPersist()) {\n const cached = await store.restore();\n value = (cached == null) ? value : cached;\n }\n }\n // we have a store for the Arc now\n arc.addStore(meta.name, store);\n // it may need a starting value\n if (value !== undefined) {\n log(`setting data to:`, value);\n store.data = value;\n }\n }\n static createStore(runtime, meta) {\n // we need to create this Store\n const store = runtime.createStore(meta);\n runtime.addStore(meta.name, store);\n return store;\n }\n static async derealizeStore(runtime, arc, meta) {\n log(`derealizeStore: derealizing \"${meta.name}\"`);\n runtime.removeStore(meta.name);\n arc.removeStore(meta.name);\n }\n static constructMeta(runtime, arc, rawMeta) {\n const meta = {\n ...rawMeta,\n arcid: arc.id,\n uid: runtime.uid,\n };\n return {\n ...meta,\n owner: meta.uid,\n shareid: `${meta.name}:${meta.arcid}:${meta.uid}`\n };\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'ParticleCook', '#5fa530');\nexport class ParticleCook {\n static async execute(runtime, arc, particles) {\n // serial\n for (const particle of particles) {\n await this.realizeParticle(runtime, arc, particle);\n }\n // parallel\n //return Promise.all(particles.map(particle => this.realizeParticle(runtime, arc, particle)));\n }\n static async realizeParticle(runtime, arc, node) {\n log('realizedParticle:', node.id);\n // convert spec to metadata\n const meta = this.specToMeta(node.spec);\n meta.container ||= node.container;\n // make a (hosted) particle\n return runtime.bootstrapParticle(arc, node.id, meta);\n }\n static specToMeta(spec) {\n if (spec.$bindings) {\n console.warn(`Particle '${spec.$kind}' spec contains deprecated $bindings property (${JSON.stringify(spec.$bindings)})`);\n }\n // TODO(sjmiles): impedance mismatch here is likely to cause problems\n const { $kind: kind, $container: container, $staticInputs: staticInputs } = spec;\n const inputs = this.formatBindings(spec.$inputs);\n const outputs = this.formatBindings(spec.$outputs);\n return { kind, staticInputs, inputs, outputs, container };\n }\n static formatBindings(bindings) {\n return bindings?.map?.(binding => typeof binding === 'string' ? { [binding]: binding } : binding);\n }\n static async evacipate(runtime, arc, particles) {\n return Promise.all(particles.map(particle => this.derealizeParticle(runtime, arc, particle)));\n }\n static async derealizeParticle(runtime, arc, node) {\n arc.removeHost(node.id);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { Parser } from './RecipeParser.js';\nimport { StoreCook } from './StoreCook.js';\nimport { ParticleCook } from './ParticleCook.js';\nconst log = logFactory(logFactory.flags.recipe, 'Chef', '#087f23');\nexport class Chef {\n static async execute(recipe, runtime, arc) {\n if (arc instanceof Promise) {\n log.error('`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.');\n return;\n }\n //log.groupCollapsed('executing recipe...', recipe.$meta);\n log('|-->...| executing recipe: ', recipe.$meta ?? '');\n const plan = new Parser(recipe);\n // `store` preparation\n await StoreCook.execute(runtime, arc, plan.stores);\n // `particle` preparation\n await ParticleCook.execute(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): what do we use this for?\n arc.meta = { ...arc.meta, ...plan.meta };\n log('|...-->| recipe complete: ', recipe.$meta ?? '');\n //log.groupEnd();\n }\n static async evacipate(recipe, runtime, arc) {\n //log.groupCollapsed('evacipating recipe...', recipe.$meta);\n log('|-->...| evacipating recipe: ', recipe.$meta);\n // TODO(sjmiles): this is work we already did\n const plan = new Parser(recipe);\n // `store` work\n // TODO(sjmiles): not sure what stores are unique to this plan\n await StoreCook.evacipate(runtime, arc, plan.stores);\n // `particle` work\n await ParticleCook.evacipate(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): doh\n //arc.meta = {...arc.meta, ...plan.meta};\n log('|...-->| recipe evacipated: ', recipe.$meta);\n //log.groupEnd();\n }\n static async executeAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.execute(recipe, runtime, arc);\n }\n }\n static async evacipateAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.evacipate(recipe, runtime, arc);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Paths } from '../utils/paths.js';\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.code, 'code', 'gold', '#333');\nconst defaultParticleBasePath = '$arcs/core/Particle.js';\n// acquire particle code\n// `kind` describes the particle\n// `options.code` may simply provide code directly\nexport const requireParticleImplCode = async (kind, options) => {\n const code = options?.code || await fetchParticleCode(kind);\n // TODO(sjmiles): brittle content processing, needs to be documented\n return code.slice(code.indexOf('({'));\n};\nexport const fetchParticleCode = async (kind) => {\n if (kind) {\n return await maybeFetchParticleCode(kind);\n }\n log.error(`fetchParticleCode: empty 'kind'`);\n};\nexport const maybeFetchParticleCode = async (kind) => {\n const path = pathForKind(kind);\n try {\n const response = await fetch(path);\n if (response.ok) {\n return await response.text();\n }\n else {\n throw '';\n }\n }\n catch (x) {\n log.error(`could not locate implementation for particle \"${kind}\" [${path}]`);\n }\n};\nexport const pathForKind = (kind) => {\n if (kind) {\n if (!'$./'.includes(kind[0]) && !kind.includes('://')) {\n kind = `$library/${kind}`;\n }\n if (!kind?.split('/').pop().includes('.')) {\n kind = `${kind}.js`;\n }\n return Paths.resolve(kind);\n }\n return '404';\n};\n// acquire Particle.js\nexport const requireParticleBaseCode = async (sourcePath) => {\n if (!requireParticleBaseCode.source) {\n const path = Paths.resolve(sourcePath || defaultParticleBasePath);\n log('particle base code path: ', path);\n const response = await fetch(path);\n const moduleText = await response.text() + \"\\n//# sourceURL=\" + path + \"\\n\";\n requireParticleBaseCode.source = moduleText.replace(/export /g, '');\n }\n return requireParticleBaseCode.source;\n};\nrequireParticleBaseCode.source = null;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const PathMapper = class {\n map;\n constructor(root) {\n this.map = {};\n this.setRoot(root);\n }\n add(mappings) {\n Object.assign(this.map, mappings || {});\n }\n resolve(path) {\n let last;\n do {\n path = this._resolve(last = path);\n } while (last !== path);\n return path;\n }\n _resolve(path) {\n const bits = path.split('/');\n const top = bits.shift();\n const prefix = this.map[top] || top;\n return [prefix, ...bits].join('/');\n }\n setRoot(root) {\n if (root.length && root[root.length - 1] === '/') {\n root = root.slice(0, -1);\n }\n this.add({\n '$root': root,\n '$arcs': root\n });\n }\n getAbsoluteHereUrl(meta, depth) {\n // you are here\n const localRelative = meta.url.split('/').slice(0, -(depth ?? 1)).join('/');\n if (!globalThis?.document) {\n return localRelative;\n }\n else {\n // document root is here\n let base = document.URL;\n // if document URL has a filename, remove it\n if (base[base.length - 1] !== '/') {\n base = `${base.split('/').slice(0, -1).join('/')}/`;\n }\n // create absoute path to here (aka 'local')\n let localAbsolute = new URL(localRelative, base).href;\n // no trailing slash!\n if (localAbsolute[localAbsolute.length - 1] === '/') {\n localAbsolute = localAbsolute.slice(0, -1);\n }\n return localAbsolute;\n }\n }\n};\nconst root = import.meta.url.split('/').slice(0, -3).join('/');\nexport const Paths = globalThis['Paths'] = new PathMapper(root);\nPaths.add(globalThis.config?.paths);\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport * from './date.js';\nexport * from './id.js';\nexport * from './log.js';\nexport * from './matching.js';\nexport * from './object.js';\nexport * from './paths.js';\nexport * from './rand.js';\nexport * from './task.js';\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const computeAgeString = (date, now) => {\n let deltaTime = Math.round((now - date) / 1000);\n if (isNaN(deltaTime)) {\n return `\u2022`;\n }\n let plural = '';\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} second${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} minute${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 24) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} hour${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 24);\n if (deltaTime < 30) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} day${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 30);\n if (deltaTime < 12) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} month${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 12);\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} year${plural} ago`;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/**\n * Perform `action` if `delay` ms have elapsed since last debounce call for `key`.\n *\n * ```\n * // invoke 'task' one second after last time this line executed\n * this.debounceTask = debounce(this.debounceTask, task, 1000);\n * ```\n */\nexport const debounce = (key, action, delay) => {\n if (key) {\n clearTimeout(key);\n }\n if (action && delay) {\n return setTimeout(action, delay);\n }\n};\nexport const async = task => {\n return async (...args) => {\n await Promise.resolve();\n task(...args);\n };\n};\nexport const asyncTask = (task, delayMs) => {\n setTimeout(task, delayMs ?? 0);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n\nexport * from '../js/Runtime.js';\nexport * from '../js/core/EventEmitter.js';\nexport * from '../js/core/Store.js';\nexport * from '../js/core/Arc.js';\nexport * from '../js/core/Host.js';\nexport * from '../js/core/Decorator.js';\nexport * from '../js/recipe/Chef.js';\nexport * from '../js/recipe/ParticleCook.js';\nexport * from '../js/recipe/StoreCook.js';\nexport * from '../js/recipe/RecipeParser.js';\nexport * as code from '../js/isolation/code.js';\n\nimport * as utils from '../js/utils/utils.js';\nconst {logFactory, Paths} = utils;\nexport {logFactory, Paths, utils};\n\nconst root = import.meta.url.split('/').slice(0, -1).join('/');\nPaths.setRoot(root);\n"], - "mappings": "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UC,EACV,OAAO,WAAWD,EAAQC,CAAK,CAEvC,EACaC,GAAQC,GACV,SAAUC,IAAS,CACtB,MAAM,QAAQ,QAAQ,EACtBD,EAAK,GAAGC,CAAI,CAChB,EAESC,GAAY,CAACF,EAAMG,IAAY,CACxC,WAAWH,EAAMG,GAAW,CAAC,CACjC,ECTA,GAAM,CAAC,WAAAC,GAAY,MAAAC,EAAK,EAAIC,EAG5B,IAAMC,GAAO,YAAY,IAAI,MAAM,GAAG,EAAE,MAAM,EAAG,EAAE,EAAE,KAAK,GAAG,EAC7DC,GAAM,QAAQD,EAAI", + "sourcesContent": ["/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport class EventEmitter {\n // map of event name to listener array\n listeners = {};\n getEventListeners(eventName) {\n return this.listeners[eventName] || (this.listeners[eventName] = []);\n }\n fire(eventName, ...args) {\n const listeners = this.getEventListeners(eventName);\n if (listeners?.forEach) {\n listeners.forEach(listener => listener(...args));\n }\n }\n listen(eventName, listener, listenerName) {\n const listeners = this.getEventListeners(eventName);\n listeners.push(listener);\n listener._name = listenerName || '(unnamed listener)';\n return listener;\n }\n unlisten(eventName, listener) {\n const list = this.getEventListeners(eventName);\n const index = (typeof listener === 'string') ? list.findIndex(l => l._name === listener) : list.indexOf(listener);\n if (index >= 0) {\n list.splice(index, 1);\n }\n else {\n console.warn('failed to unlisten from', eventName);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const logKinds = ['log', 'group', 'groupCollapsed', 'groupEnd', 'dir'];\nexport const errKinds = ['warn', 'error'];\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logKinds, errKinds } from './types.js';\nconst { fromEntries } = Object;\nconst _logFactory = (enable, preamble, bg, color, kind = 'log') => {\n if (typeof enable === 'string') {\n enable = logFactory.flags[enable];\n }\n if (!enable) {\n return () => { };\n }\n if (kind === 'dir') {\n return console.dir.bind(console);\n }\n const style = `background: ${bg || 'gray'}; color: ${color || 'white'}; padding: 1px 6px 2px 7px; border-radius: 6px 0 0 6px;`;\n return console[kind].bind(console, `%c${preamble}`, style);\n};\nexport const logFactory = (enable, preamble, bg = '', color = '') => {\n const debugLoggers = fromEntries(logKinds.map(kind => [kind, _logFactory(enable, preamble, bg, color, kind)]));\n const errorLoggers = fromEntries(errKinds.map(kind => [kind, _logFactory(true, preamble, bg, color, kind)]));\n const loggers = { ...debugLoggers, ...errorLoggers };\n // Inject `log` as default, keeping all loggers available to be invoked by name.\n const log = loggers.log;\n Object.assign(log, loggers);\n return log;\n};\nlogFactory.flags = globalThis.config?.logFlags || {};\n", "/**\n * @license\n * Copyright (c) 2022 Google LLC All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\nimport { EventEmitter } from './EventEmitter.js';\nimport { logFactory } from '../utils/log.js';\nconst customLogFactory = (id) => logFactory(logFactory.flags.arc, `Arc (${id})`, 'slateblue');\nconst { assign, create } = Object;\nconst entries = (o) => Object.entries(o ?? Object);\nconst keys = (o) => Object.keys(o ?? Object);\nconst values = (o) => Object.values(o ?? Object);\nconst nob = () => create(null);\nexport class Arc extends EventEmitter {\n log;\n id;\n meta;\n stores;\n hosts;\n surface;\n composer;\n hostService;\n constructor(id, meta, surface) {\n super();\n this.id = id;\n this.meta = meta;\n this.surface = surface;\n this.hosts = nob();\n this.stores = nob();\n this.log = customLogFactory(id);\n }\n async addHost(host, surface) {\n // to support hosts we need a composer\n await this.ensureComposer();\n // bookkeep\n this.hosts[host.id] = host;\n host.arc = this;\n // TODO(sjmiles): support per host surfacing?\n //await host.bindToSurface(surface ?? this.surface);\n // begin work\n this.updateHost(host);\n return host;\n }\n async ensureComposer() {\n if (!this.composer && this.surface) {\n // create composer\n this.composer = await this.surface.createComposer('root');\n // pipeline for events from composer to this.onevent\n // TODO(sjmiles): use 'bind' to avoid a closure and improve the stack trace\n this.composer.onevent = this.onevent.bind(this);\n }\n }\n rerender() {\n values(this.hosts).forEach(h => h.rerender());\n }\n removeHost(id) {\n this.hosts[id]?.detach();\n delete this.hosts[id];\n }\n addStore(storeId, store) {\n if (store && !this.stores[storeId]) {\n this.stores[storeId] = store;\n store.listen('change', () => this.storeChanged(storeId, store), this.id);\n }\n }\n removeStore(storeId) {\n const store = this.stores[storeId];\n if (store) {\n store.unlisten('change', this.id);\n }\n delete this.stores[storeId];\n }\n // TODO(sjmiles): 2nd param is used in overrides, make explicit\n storeChanged(storeId, store) {\n this.log(`storeChanged: \"${storeId}\"`);\n const isBound = inputs => inputs && inputs.some(input => input && (values(input)[0] == storeId || keys(input)[0] == storeId));\n values(this.hosts).forEach(host => {\n const inputs = host.meta?.inputs;\n if (inputs === '*' || isBound(inputs)) {\n this.log(`host \"${host.id}\" has interest in \"${storeId}\"`);\n // TODO(sjmiles): we only have to update inputs for storeId, we lose efficiency here\n this.updateHost(host);\n }\n });\n this.fire('store-changed', storeId);\n }\n updateParticleMeta(hostId, meta) {\n const host = this.hosts[hostId];\n host.meta = meta;\n this.updateHost(host);\n }\n updateHost(host) {\n host.inputs = this.computeInputs(host);\n }\n // TODO(sjmiles): debounce? (update is sync-debounced already)\n // complement to `assignOutputs`\n computeInputs(host) {\n const inputs = nob();\n const inputBindings = host.meta?.inputs;\n if (inputBindings === '*') {\n // TODO(sjmiles): we could make the contract that the bindAll inputs are\n // names (or names + meta) only. The Particle could look up values via\n // service (to reduce throughput requirements)\n entries(this.stores).forEach(([name, store]) => inputs[name] = store.pojo);\n }\n else {\n const staticInputs = host.meta?.staticInputs;\n assign(inputs, staticInputs);\n if (inputBindings) {\n inputBindings.forEach(input => input && this.computeInput(entries(input)[0], inputs));\n this.log(`computeInputs(${host.id}) =`, inputs);\n }\n }\n return inputs;\n }\n computeInput([name, binding], inputs) {\n const storeName = binding || name;\n const store = this.stores[storeName];\n if (store) {\n inputs[name] = store.pojo;\n }\n else {\n // TODO(sjmiles): is this ok or not?\n //this.log.warn(`computeInput: \"${storeName}\" (bound to \"${name}\") not found`);\n }\n }\n // complement to `computeInputs`\n assignOutputs({ id, meta }, outputs) {\n const names = keys(outputs);\n if (meta?.outputs && names.length) {\n names.forEach(name => this.assignOutput(name, outputs[name], meta.outputs));\n this.log(`[end][${id}] assignOutputs:`, outputs);\n }\n }\n assignOutput(name, output, outputs) {\n if (output !== undefined) {\n const binding = this.findOutputByName(outputs, name) || name;\n const store = this.stores[binding];\n if (!store) {\n if (outputs?.[name]) {\n this.log.warn(`assignOutputs: no \"${binding}\" store for output \"${name}\"`);\n }\n }\n else {\n // Note: users can mess up output data in any way they see fit, so we should\n // probably invent `outputCleansing`.\n this.log(`assignOutputs: \"${name}\" is dirty, updating Store \"${binding}\"`, output);\n store.data = output;\n }\n }\n }\n findOutputByName(outputs, name) {\n const output = outputs?.find(output => keys(output || 0)[0] === name);\n if (output) {\n return values(output)[0];\n }\n }\n async render(packet) {\n if (this.composer) {\n this.composer.render({ ...packet, arcid: this.id });\n }\n else {\n //this.log.low('render called, but composer is null', packet);\n }\n }\n onevent(pid, eventlet) {\n const host = this.hosts[pid];\n if (host) {\n host.handleEvent(eventlet);\n }\n }\n async service(host, request) {\n let result = await this.surface?.service(request);\n if (result === undefined) {\n result = this.hostService?.(host, request);\n }\n return result;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/*\n * update the fields of `obj` with the fields of `data`,\n * perturbing `obj` as little as possible (since it might be a magic proxy thing\n * like an Automerge document)\n */\nexport const shallowUpdate = (obj, data) => {\n let result = data;\n if (!data) {\n //\n }\n else if (Array.isArray(data)) {\n if (!Array.isArray(obj)) {\n // TODO(sjmiles): eek, very perturbing to obj\n obj = [];\n }\n for (let i = 0; i < data.length; i++) {\n const value = data[i];\n if (obj[i] !== value) {\n obj[i] = value;\n }\n }\n const overage = obj.length - data.length;\n if (overage > 0) {\n obj.splice(data.length, overage);\n }\n }\n else if (typeof data === 'object') {\n result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n const seen = {};\n // for each key in input data ...\n Object.keys(data).forEach(key => {\n // copy that data into output\n result[key] = data[key];\n // remember the key\n seen[key] = true;\n });\n // for each key in the output data...\n Object.keys(result).forEach(key => {\n // if this key was not in the input, remove it\n if (!seen[key]) {\n delete result[key];\n }\n });\n }\n return result;\n};\nexport const shallowMerge = (obj, data) => {\n if (data == null) {\n return null;\n }\n if (typeof data === 'object') {\n const result = (obj && typeof obj === 'object') ? obj : Object.create(null);\n Object.keys(data).forEach(key => result[key] = data[key]);\n return result;\n }\n return data;\n};\nexport function deepCopy(datum) {\n if (!datum) {\n return datum;\n }\n else if (Array.isArray(datum)) {\n // This is trivially type safe but tsc needs help\n return datum.map(element => deepCopy(element));\n }\n else if (typeof datum === 'object') {\n const clone = Object.create(null);\n Object.entries(datum).forEach(([key, value]) => {\n clone[key] = deepCopy(value);\n });\n return clone;\n }\n else {\n return datum;\n }\n}\nexport const deepEqual = (a, b) => {\n const type = typeof a;\n // must be same type to be equal\n if (type !== typeof b) {\n return false;\n }\n // we are `deep` because we recursively study object types\n if (type === 'object' && a && b) {\n const aProps = Object.getOwnPropertyNames(a);\n const bProps = Object.getOwnPropertyNames(b);\n // equal if same # of props, and no prop is not deepEqual\n return (aProps.length == bProps.length) && !aProps.some(name => !deepEqual(a[name], b[name]));\n }\n // finally, perform simple comparison\n return (a === b);\n};\nexport const deepUndefinedToNull = (obj) => {\n if (obj === undefined) {\n return null;\n }\n if (obj && (typeof obj === 'object')) {\n // we are `deep` because we recursively study object types\n const props = Object.getOwnPropertyNames(obj);\n props.forEach(name => {\n const prop = obj[name];\n if (prop === undefined) {\n delete obj[name];\n //obj[name] = null;\n }\n else {\n deepUndefinedToNull(prop);\n }\n });\n }\n return obj;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nconst { floor, pow, random } = Math;\n// random n-digit number\nexport const key = (digits) => floor((1 + random() * 9) * pow(10, digits - 1));\n// random integer from [0..range)\nexport const irand = (range) => floor(random() * range);\n// random element from array\nexport const arand = (array) => array[irand(array.length)];\n// test if event has occured, where `probability` is between [0..1]\nexport const prob = (probability) => Boolean(random() < probability);\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepCopy } from '../utils/object.js';\nconst log = logFactory(logFactory.flags.decorator, 'Decorator', 'plum');\nconst { values, entries } = Object;\nconst opaqueData = {};\nexport const Decorator = {\n setOpaqueData(name, data) {\n opaqueData[name] = data; //deepCopy(data);\n return name;\n },\n getOpaqueData(name) {\n return opaqueData[name];\n },\n maybeDecorateModel(model, particle) {\n if (model && !Array.isArray(model)) {\n // for each item in model, regardless of key\n values(model).forEach((item) => {\n // is an object?\n if (item && (typeof item === 'object')) {\n // are there sub-models\n if (item['models']) {\n // the decorate this item\n log('applying decorator(s) to list:', item);\n this.maybeDecorateItem(item, particle);\n }\n else {\n // otherwise, check if there are sub-items to decorate\n if (model?.filter || model?.decorator || model?.collateBy) {\n log('scanning for lists in sub-model:', item);\n this.maybeDecorateModel(item, particle);\n }\n }\n }\n });\n }\n // possibly decorated model\n return model;\n },\n maybeDecorateItem(item, particle) {\n let models = (typeof item.models === 'string') ? this.getOpaqueData(item.models) : item.models;\n if (models) {\n // do a decorator\n models = maybeDecorate(models, item.decorator, particle);\n // do a filter\n models = maybeFilter(models, item.filter, particle.impl);\n // do a collator\n models = maybeCollateBy(models, item);\n // mutate items\n item.models = models;\n //console.log(JSON.stringify(models, null, ' '));\n }\n },\n};\nconst maybeDecorate = (models, decorator, particle) => {\n decorator = particle.impl[decorator] ?? decorator;\n const { inputs, state } = particle.internal;\n if (decorator) {\n // TODO(cromwellian): Could be expensive to do everything, store responsibility?\n const immutableInputs = Object.freeze(deepCopy(inputs));\n // we don't want the decorator to have access to mutable globals\n const immutableState = Object.freeze(deepCopy(state));\n // models become decorous\n models = models.map(model => {\n // use previously mutated data or initialize\n // TODO(cromwellian): I'd like to do Object.freeze() here, also somehow not mutate the models inplace\n // Possibly have setOpaqueData wrap the data so the privateData lives on the wrapper + internal immutable data\n model.privateData = model.privateData || {};\n // TODO(cromwellian): also could be done once during setOpaqueData() if we can track privateData differently\n const immutableModel = Object.freeze(deepCopy(model));\n const decorated = decorator(immutableModel, immutableInputs, immutableState);\n // set new privateData from returned\n model.privateData = decorated.privateData;\n return { ...decorated, ...model, };\n });\n // sort (possible that all values undefined)\n models.sort(sortByLc('sortKey'));\n log('decoration was performed');\n }\n //models.forEach(model => delete model.privateData);\n return models;\n};\nconst maybeFilter = (models, filter, impl) => {\n filter = impl[filter] ?? filter;\n if (filter && models) {\n // models become filtrated\n models = models.filter(filter);\n }\n return models;\n};\nconst maybeCollateBy = (models, item) => {\n // construct requested sub-lists\n entries(item).forEach(([name, collator]) => {\n // generate named collations for items of the form `[name]: {collateBy}`\n if (collator?.['collateBy']) {\n // group the models into buckets based on the model-field named by `collateBy`\n const collation = collate(models, collator['collateBy']);\n models = collationToRenderModels(collation, name, collator['$template']);\n }\n });\n return models;\n};\nconst sortByLc = key => (a, b) => sort(String(a[key]).toLowerCase(), String(b[key]).toLowerCase());\n//const sortBy = key => (a, b) => sort(a[key], b[key]);\nconst sort = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst collate = (models, collateBy) => {\n const collation = {};\n models.forEach(model => {\n const keyValue = model[collateBy];\n if (keyValue) {\n const category = collation[keyValue] || (collation[keyValue] = []);\n category.push(model);\n }\n });\n return collation;\n};\nconst collationToRenderModels = (collation, name, $template) => {\n return entries(collation).map(([key, models]) => ({\n key,\n [name]: { models, $template },\n single: !(models['length'] !== 1),\n ...models?.[0]\n }));\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { deepEqual, deepCopy } from '../utils/object.js';\nimport { arand } from '../utils/rand.js';\nimport { EventEmitter } from './EventEmitter.js';\nimport { Decorator } from './Decorator.js';\nconst { entries, keys } = Object;\nconst customLogFactory = (id) => logFactory(logFactory.flags.host, `Host (${id})`, arand(['#5a189a', '#51168b', '#48137b', '#6b2fa4', '#7b46ae', '#3f116c']));\n/**\n * Host owns metadata (e.g. `id`, `container`) that its Particle is not allowed to access.\n * Host knows how to talk, asynchronously, to its Particle (potentially using a bus).\n**/\n/* TODO(sjmiles):\nUpdate Cycle Documented Briefly\n1. when a Store changes it invokes it's listeners\n2. when an Arc hears a Store change, it updates Hosts bound to the Store\n3. Arc updates Host by creating an `inputs` object from Stores and metadata\n - ignores fact inputs are accumulated\n - ignores information about which Store has updated\n4. `inputs` object is assigned to `hosts.inputs` \uD83D\uDE43\n5. Host does an expensive `deepEqual` equality check. Turning on `host` logging should reveal `this.log('inputs are not interesting, skipping update');` if data is caught in this trap\n - we can use reference testing here if we are more careful\n about using immutable data\n6. the particle.inputs are assigned (but is really a *merge*)\n*/\nexport class Host extends EventEmitter {\n arc;\n id;\n lastOutput;\n lastPacket;\n lastRenderModel;\n log;\n meta;\n particle;\n constructor(id) {\n super();\n this.log = customLogFactory(id);\n this.id = id;\n }\n onevent(eventlet) {\n this.arc?.onevent(eventlet);\n this.fire('eventlet', eventlet);\n }\n // Particle and ParticleMeta are separate, host specifically integrates these on behalf of Particle\n installParticle(particle, meta) {\n if (this.particle) {\n this.detachParticle();\n }\n if (particle) {\n this.particle = particle;\n this.meta = meta || this.meta;\n }\n }\n get container() {\n return this.meta?.container || 'root';\n }\n detach() {\n this.detachParticle();\n this.arc = null;\n }\n detachParticle() {\n if (this.particle) {\n this.render({ $clear: true });\n this.particle = null;\n this.meta = null;\n }\n }\n async service(request) {\n if (request?.decorate) {\n return Decorator.maybeDecorateModel(request.model, this.particle);\n }\n return this.arc?.service(this, request);\n }\n output(outputModel, renderModel) {\n if (outputModel) {\n this.lastOutput = outputModel;\n this.arc?.assignOutputs(this, outputModel);\n this.fire('output', outputModel);\n }\n if (this.template) {\n Decorator.maybeDecorateModel(renderModel, this.particle);\n this.lastRenderModel = { ...renderModel };\n this.render(renderModel);\n }\n }\n rerender() {\n // does not re-render Frame/Slot content\n // you probably want Arc::rerender\n if (this.lastRenderModel) {\n this.render(this.lastRenderModel);\n }\n }\n render(model) {\n const { id, container, template } = this;\n const content = { model, template };\n const packet = { id, container, content };\n this.fire('render', packet);\n this.arc?.render(packet);\n this.lastPacket = packet;\n }\n set inputs(inputs) {\n if (this.particle && inputs) {\n const lastInputs = this.particle.internal.inputs;\n if (this.dirtyCheck(inputs, lastInputs, this.lastOutput)) {\n this.particle.inputs = deepCopy({ ...this.meta?.staticInputs, ...inputs });\n this.fire('inputs-changed');\n }\n else {\n this.log('inputs are uninteresting, skipping update');\n }\n }\n }\n dirtyCheck(inputs, lastInputs, lastOutput) {\n const dirtyBits = ([n, v]) => (lastOutput?.[n] && !deepEqual(lastOutput[n], v))\n || !deepEqual(lastInputs?.[n], v);\n return !lastInputs\n || entries(inputs).length !== this.lastInputsLength(lastInputs)\n || entries(inputs).some(dirtyBits);\n }\n lastInputsLength(lastInputs) {\n return keys(lastInputs).filter(key => !this.meta?.staticInputs?.[key] && key !== 'eventlet').length;\n }\n get config() {\n return this.particle?.config;\n }\n get template() {\n return this.config?.template;\n }\n invalidate() {\n this.particle?.invalidate();\n }\n handleEvent(eventlet) {\n return this.particle?.handleEvent(eventlet);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { EventEmitter } from './EventEmitter.js';\nconst { create, keys } = Object;\nconst { stringify, parse } = JSON;\nexport class DataStore extends EventEmitter {\n privateData;\n constructor() {\n super();\n }\n setPrivateData(data) {\n this.privateData = data;\n }\n set data(data) {\n this.setPrivateData(data);\n }\n get data() {\n return this.privateData;\n }\n toString() {\n return this.pretty;\n }\n get isObject() {\n return this.data && typeof this.data === 'object';\n }\n get pojo() {\n return this.data;\n }\n get json() {\n return stringify(this.data);\n }\n set json(json) {\n let value = null;\n try {\n value = parse(json);\n }\n catch (x) {\n //\n }\n this.data = value;\n }\n get pretty() {\n const sorted = {};\n const pojo = this.pojo;\n keys(pojo).sort().forEach(key => sorted[key] = pojo[key]);\n return stringify(sorted, null, ' ');\n }\n}\nclass ObservableStore extends DataStore {\n change(mutator) {\n mutator(this);\n this.doChange();\n }\n doChange() {\n this.fire('change', this);\n this.onChange(this);\n }\n onChange(store) {\n // override\n }\n set data(data) {\n this.change(self => self.setPrivateData(data));\n }\n // TODO(sjmiles): one of the compile/build/bundle tools\n // evacipates the inherited getter, so we clone it\n get data() {\n return this['privateData'];\n }\n set(key, value) {\n if (!this.data) {\n this.setPrivateData(create(null));\n }\n if (value !== undefined) {\n this.change(self => self.data[key] = value);\n }\n else {\n this.delete(key);\n }\n }\n delete(key) {\n this.change(doc => delete doc.data[key]);\n }\n}\nclass PersistableStore extends ObservableStore {\n meta;\n constructor(meta) {\n super();\n this.meta = { ...meta };\n }\n toString() {\n return `${JSON.stringify(this.meta, null, ' ')}, ${this.pretty}`;\n }\n get tags() {\n return this.meta.tags ?? (this.meta.tags = []);\n }\n is(...tags) {\n // true if every member of `tags` is also in `this.tags`\n return tags.every(tag => this.tags.includes(tag));\n }\n isCollection() {\n return this.meta.type?.[0] === '[';\n }\n shouldPersist() {\n return this.is('persisted') && !this.is('volatile');\n }\n async doChange() {\n // do not await\n this.persist();\n return super.doChange();\n }\n // TODO(sjmiles): as of now the persist/restore methods\n // are bound in Runtime:addStore\n async persist() {\n }\n async restore( /*value: any*/) {\n }\n // delete() {\n // this.persistor?.remove(this);\n // }\n save() {\n return this.json;\n }\n load(serial, defaultValue) {\n let value = defaultValue;\n try {\n if (serial) {\n value = parse(serial);\n }\n }\n catch (x) {\n //\n }\n if (value !== undefined) {\n this.data = value;\n }\n }\n}\nexport class Store extends PersistableStore {\n}\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { irand } from \"./rand.js\";\nexport const makeId = (pairs, digits, delim) => {\n pairs = pairs || 2;\n digits = digits || 2;\n delim = delim || '-';\n const min = Math.pow(10, digits - 1);\n const range = Math.pow(10, digits) - min;\n const result = [];\n for (let i = 0; i < pairs; i++) {\n result.push(`${irand(range - min) + min}`);\n }\n return result.join(delim);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Arc } from './core/Arc.js';\nimport { Host } from './core/Host.js';\nimport { Store } from './core/Store.js';\nimport { EventEmitter } from './core/EventEmitter.js';\nimport { logFactory } from './utils/log.js';\nimport { makeId } from './utils/id.js';\nconst log = logFactory(logFactory.flags.runtime, 'runtime', '#873600');\nconst particleFactoryCache = {};\nconst storeFactories = {};\nconst { keys } = Object;\nexport class Runtime extends EventEmitter {\n log;\n uid; // user id\n nid; // network id\n arcs;\n stores;\n peers;\n shares;\n endpoint;\n network;\n surfaces;\n persistor;\n prettyUid;\n static securityLockdown;\n static particleIndustry;\n static particleOptions;\n constructor(uid) {\n uid = uid || 'user';\n super();\n this.arcs = {};\n this.surfaces = {};\n this.stores = {};\n this.peers = new Set();\n this.shares = new Set();\n this.setUid(uid);\n this.log = logFactory(logFactory.flags.runtime, `runtime:[${this.prettyUid}]`, '#873600');\n //Runtime.securityLockdown?.(Runtime.particleOptions);\n }\n setUid(uid) {\n this.uid = uid;\n this.nid = `${uid}:${makeId(1, 2)}`;\n this.prettyUid = uid.substring(0, uid.indexOf('@') + 1) || uid;\n }\n async bootstrapArc(name, meta, surface, service) {\n // make an arc on `surface`\n const arc = new Arc(name, meta, surface);\n // install service handler\n arc.hostService = this.serviceFactory(service);\n // add `arc` to runtime\n await this.addArc(arc);\n // fin\n return arc;\n }\n serviceFactory(service) {\n return async (host, request) => service.handle(this, host, request);\n }\n // TODO(sjmiles): duplication vis a vis `installParticle`\n // used by? ... [ParticleCook.js]\n async bootstrapParticle(arc, id, meta) {\n // make a host\n const host = new Host(id);\n // make a particle\n await this.marshalParticle(host, meta);\n // add `host` to `arc`\n await arc.addHost(host);\n // report\n log('bootstrapped particle', id);\n //log(host);\n return host;\n }\n // no-op surface mapping\n addSurface(id, surface) {\n this.surfaces[id] = surface;\n }\n getSurface(id) {\n return this.surfaces[id];\n }\n // map arcs by arc.id\n addArc(arc) {\n const { id } = arc;\n if (id && !this.arcs[id]) {\n return this.arcs[id] = arc;\n }\n throw `arc has no id, or id \"${id}\" is already in use`;\n }\n removeArc(arc) {\n const { id } = arc;\n if (!id || !this.arcs[id]) {\n throw !id ? `arc has no id` : `id \"${id}\" is not in use`;\n }\n delete this.arcs[id];\n }\n // create a particle inside of host\n async marshalParticle(host, particleMeta) {\n const particle = await this.createParticle(host, particleMeta.kind);\n return host.installParticle(particle, particleMeta);\n }\n // create a host, install a particle, add host to arc\n // TODO(sjmiles): duplication vis a vis `bootstrapParticle`\n // used by? ... [ArcsWorker.js]\n async installParticle(arc, particleMeta, name) {\n this.log('installParticle', name, particleMeta, arc.id);\n // provide a default name\n name = name || makeId();\n // deduplicate name\n if (arc.hosts[name]) {\n let n = 1;\n for (; (arc.hosts[`${name}-${n}`]); n++)\n ;\n name = `${name}-${n}`;\n }\n // build the structure\n const host = new Host(name);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n }\n // TODO(sjmiles): third version to rule them all; bring your own host\n async addParticle(arc, host, particleMeta, name) {\n this.log('addParticle', arc.id, name, particleMeta, arc.id);\n await this.marshalParticle(host, particleMeta);\n await arc.addHost(host);\n return host;\n // this.log('addParticle', name, particleMeta, arc.id);\n // // provide a default name\n // name = name || makeId();\n // // deduplicate name\n // if (arc.hosts[name]) {\n // let n = 1;\n // for (; (arc.hosts[`${name}-${n}`]); n++);\n // name = `${name}-${n}`;\n // }\n // // build the structure\n // const host = new Host(name);\n // await this.marshalParticle(host, particleMeta);\n // await arc.addHost(host);\n // return host;\n }\n idFromName(name, list) {\n // provide a default name\n let id = name || makeId();\n // deduplicate name\n if (list[id]) {\n let n = 1;\n for (; (list[`${id}-${n}`]); n++)\n ;\n id = `${id}-${n}`;\n }\n // return unique id\n return id;\n }\n // map a store by a Runtime-specific storeId\n // Stores have no intrinsic id\n addStore(storeId, store) {\n // if the store needs to discuss things with Runtime\n // TODO(sjmiles): this is likely unsafe for re-entry\n if (store.marshal) {\n store.marshal(this);\n }\n // bind to persist/restore functions\n store.persist = async () => this.persistStore(storeId, store);\n store.restore = async () => this.restoreStore(storeId, store);\n // override the Store's own persistor to use the runtime persistor\n // TODO(sjmiles): why?\n // if (store.persistor) {\n // store.persistor.persist = store => this.persistor?.persist(storeId, store);\n // }\n // bind this.storeChanged to store.change (and name the binding)\n const name = `${this.nid}:${storeId}-changed`;\n const onChange = this.storeChanged.bind(this, storeId);\n store.listen('change', onChange, name);\n // map the store\n this.stores[storeId] = store;\n // evaluate for sharing\n this.maybeShareStore(storeId);\n // notify listeners that a thing happened\n // TODO(sjmiles): makes no sense without id\n //this.fire('store-added', store);\n }\n async persistStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`persistStore \"${storeId}\"`);\n return this.persistor?.persist?.(storeId, store.data);\n }\n }\n async restoreStore(storeId, store) {\n if (store.shouldPersist()) {\n this.log(`restoreStore \"${storeId}\"`);\n return this.persistor?.restore?.(storeId);\n }\n }\n storeChanged(storeId, store) {\n this.log('storeChanged', storeId);\n this.network?.invalidatePeers(storeId);\n this.onStoreChange(storeId, store);\n this.fire('store-changed', { storeId, store });\n }\n // TODO(sjmiles): evacipate this method\n onStoreChange(storeId, store) {\n // override for bespoke response\n }\n do(storeId, task) {\n task(this.stores[storeId]);\n }\n removeStore(storeId) {\n this.do(storeId, store => {\n store?.unlisten('change', `${this.nid}:${storeId}-changed`);\n });\n delete this.stores[storeId];\n }\n maybeShareStore(storeId) {\n this.do(storeId, store => {\n if (store?.is('shared')) {\n this.shareStore(storeId);\n }\n });\n }\n addPeer(peerId) {\n this.peers.add(peerId);\n [...this.shares].forEach(storeId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n shareStore(storeId) {\n this.shares.add(storeId);\n [...this.peers].forEach(peerId => this.maybeShareStoreWithPeer(storeId, peerId));\n }\n maybeShareStoreWithPeer(storeId, peerId) {\n this.do(storeId, store => {\n const nid = this.uid.replace(/\\./g, '_');\n if (!store.is('private') || (peerId.startsWith(nid))) {\n this.shareStoreWithPeer(storeId, peerId);\n }\n });\n }\n shareStoreWithPeer(storeId, peerId) {\n this.network?.shareStore(storeId, peerId);\n }\n async createParticle(host, kind) {\n try {\n const factory = await this.marshalParticleFactory(kind);\n return factory?.(host);\n }\n catch (x) {\n log.error(`createParticle(${kind}):`, x);\n }\n }\n async marshalParticleFactory(kind) {\n return particleFactoryCache[kind] ?? this.lateBindParticle(kind);\n }\n lateBindParticle(kind, code) {\n const { particleOptions, particleIndustry, registerFactoryPromise } = Runtime;\n if (!particleIndustry) {\n throw `no ParticleIndustry to create '${kind}'`;\n }\n else {\n const factoryPromise = particleIndustry(kind, { ...particleOptions, code });\n registerFactoryPromise(kind, factoryPromise);\n return factoryPromise;\n }\n }\n static registerFactoryPromise(kind, factoryPromise) {\n return particleFactoryCache[kind] = factoryPromise;\n }\n requireStore(meta) {\n let store = this.stores[meta.name];\n if (!store) {\n store = this.createStore(meta);\n this.addStore(meta.name, store);\n }\n return store;\n }\n createStore(meta) {\n const key = keys(storeFactories).find(tag => meta.tags?.includes?.(tag));\n const storeClass = storeFactories[String(key)] || Store;\n return new storeClass(meta);\n }\n static registerStoreClass(tag, storeClass) {\n storeFactories[tag] = storeClass;\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'RecipeParser', 'violet');\nconst { entries, create } = Object;\nexport class Parser {\n stores;\n particles;\n slots;\n meta;\n constructor(recipe) {\n this.stores = [];\n this.particles = [];\n this.slots = [];\n this.meta = create(null);\n if (recipe) {\n this.parse(recipe);\n }\n }\n parse(recipe) {\n // `normalize` converts shorthand to longhand before parsing\n const normalized = this.normalize(recipe);\n this.parseSlotSpec(normalized, 'root', '');\n return this;\n }\n normalize(recipe) {\n if (typeof recipe !== 'object') {\n throw Error('recipe must be an Object');\n }\n // TODO(sjmiles): would be great if `normalize` normalized all the things\n return recipe;\n }\n parseSlotSpec(spec, slotName, parentName) {\n // process entries\n for (const key in spec) {\n switch (key) {\n case '$meta':\n // value is a dictionary\n this.meta = { ...this.meta, ...spec.$meta };\n break;\n case '$stores':\n // value is a StoreSpec\n this.parseStoresNode(spec.$stores);\n break;\n default: {\n // value is a ParticleSpec\n const container = parentName ? `${parentName}#${slotName}` : slotName;\n this.parseParticleSpec(container, key, spec[key]);\n break;\n }\n }\n }\n }\n parseStoresNode(stores) {\n for (const key in stores) {\n this.parseStoreSpec(key, stores[key]);\n }\n }\n parseStoreSpec(name, spec) {\n if (this.stores.find(s => s.name === name)) {\n log('duplicate store name');\n return;\n }\n const meta = {\n name,\n type: spec.$type,\n tags: spec.$tags,\n value: spec.$value\n };\n this.stores.push(meta);\n }\n parseParticleSpec(container, id, spec) {\n if (!spec.$kind) {\n log.warn(`parseParticleSpec: malformed spec has no \"kind\":`, spec);\n throw Error();\n }\n if (this.particles.find(s => s.id === id)) {\n log('duplicate particle name', id, spec);\n return;\n }\n this.particles.push({ id, container, spec });\n if (spec.$slots) {\n this.parseSlotsNode(spec.$slots, id);\n }\n }\n parseSlotsNode(slots, parent) {\n entries(slots).forEach(([key, spec]) => this.parseSlotSpec(spec, key, parent));\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport function matches(candidateMeta, targetMeta) {\n for (const property in targetMeta) {\n if (candidateMeta[property] !== targetMeta[property]) {\n return false;\n }\n }\n return true;\n}\n;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { matches } from '../utils/matching.js';\nconst log = logFactory(logFactory.flags.recipe, 'StoreCook', '#99bb15');\nconst { values } = Object;\nconst mapStore = (runtime, { name, type }) => {\n return findStores(runtime, { name, type })?.[0];\n};\nconst findStores = (runtime, criteria) => {\n return values(runtime.stores).filter(store => storeMatches(store, criteria));\n};\nconst storeMatches = (store, criteria) => {\n // TODO(b/244191110): Type matching API to be wired here.\n const { type, ...other } = criteria;\n if (typeMatches(type, store?.meta.type)) {\n // generic object comparison\n return matches(store?.meta, other);\n }\n};\nconst typeMatches = (typeA, typeB) => {\n const baseTypes = ['pojo', 'json'];\n return (typeA === typeB)\n || baseTypes.includes(typeA?.toLowerCase())\n || baseTypes.includes(typeB?.toLowerCase());\n};\nexport class StoreCook {\n static async execute(runtime, arc, stores) {\n return this.forEachStore(this.realizeStore, runtime, arc, stores);\n }\n static async evacipate(runtime, arc, stores) {\n return this.forEachStore(this.derealizeStore, runtime, arc, stores);\n }\n static async forEachStore(task, runtime, arc, stores) {\n return Promise.all(stores.map(store => task.call(this, runtime, arc, store)));\n }\n static async realizeStore(runtime, arc, rawMeta) {\n // potential initialization value\n let value;\n // build a StoreMeta out of parts\n const meta = this.constructMeta(runtime, arc, rawMeta);\n // do we already own this Store?\n let store = mapStore(runtime, meta);\n if (store) {\n // use a Store\n log(`realizeStore: mapping \"${rawMeta.name}\" to \"${store.meta.name}\"`);\n }\n else {\n log(`realizeStore: creating \"${meta.name}\"`);\n // create a Store\n store = StoreCook.createStore(runtime, meta);\n // default initial value comes from meta\n value = meta?.value;\n // persisted value may override default\n if (store.shouldPersist()) {\n const cached = await store.restore();\n value = (cached == null) ? value : cached;\n }\n }\n // we have a store for the Arc now\n arc.addStore(meta.name, store);\n // it may need a starting value\n if (value !== undefined) {\n log(`setting data to:`, value);\n store.data = value;\n }\n }\n static createStore(runtime, meta) {\n // we need to create this Store\n const store = runtime.createStore(meta);\n runtime.addStore(meta.name, store);\n return store;\n }\n static async derealizeStore(runtime, arc, meta) {\n log(`derealizeStore: derealizing \"${meta.name}\"`);\n runtime.removeStore(meta.name);\n arc.removeStore(meta.name);\n }\n static constructMeta(runtime, arc, rawMeta) {\n const meta = {\n ...rawMeta,\n arcid: arc.id,\n uid: runtime.uid,\n };\n return {\n ...meta,\n owner: meta.uid,\n shareid: `${meta.name}:${meta.arcid}:${meta.uid}`\n };\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.recipe, 'ParticleCook', '#5fa530');\nexport class ParticleCook {\n static async execute(runtime, arc, particles) {\n // serial\n for (const particle of particles) {\n await this.realizeParticle(runtime, arc, particle);\n }\n // parallel\n //return Promise.all(particles.map(particle => this.realizeParticle(runtime, arc, particle)));\n }\n static async realizeParticle(runtime, arc, node) {\n log('realizedParticle:', node.id);\n // convert spec to metadata\n const meta = this.specToMeta(node.spec);\n meta.container ||= node.container;\n // make a (hosted) particle\n return runtime.bootstrapParticle(arc, node.id, meta);\n }\n static specToMeta(spec) {\n if (spec.$bindings) {\n console.warn(`Particle '${spec.$kind}' spec contains deprecated $bindings property (${JSON.stringify(spec.$bindings)})`);\n }\n // TODO(sjmiles): impedance mismatch here is likely to cause problems\n const { $kind: kind, $container: container, $staticInputs: staticInputs } = spec;\n const inputs = this.formatBindings(spec.$inputs);\n const outputs = this.formatBindings(spec.$outputs);\n return { kind, staticInputs, inputs, outputs, container };\n }\n static formatBindings(bindings) {\n return bindings?.map?.(binding => typeof binding === 'string' ? { [binding]: binding } : binding);\n }\n static async evacipate(runtime, arc, particles) {\n return Promise.all(particles.map(particle => this.derealizeParticle(runtime, arc, particle)));\n }\n static async derealizeParticle(runtime, arc, node) {\n arc.removeHost(node.id);\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { logFactory } from '../utils/log.js';\nimport { Parser } from './RecipeParser.js';\nimport { StoreCook } from './StoreCook.js';\nimport { ParticleCook } from './ParticleCook.js';\nconst log = logFactory(logFactory.flags.recipe, 'Chef', '#087f23');\nexport class Chef {\n static async execute(recipe, runtime, arc) {\n if (arc instanceof Promise) {\n log.error('`arc` must be an Arc, not a Promise. Make sure `boostrapArc` is awaited.');\n return;\n }\n //log.groupCollapsed('executing recipe...', recipe.$meta);\n log('|-->...| executing recipe: ', recipe);\n const plan = new Parser(recipe);\n // `store` preparation\n await StoreCook.execute(runtime, arc, plan.stores);\n // `particle` preparation\n await ParticleCook.execute(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): what do we use this for?\n arc.meta = { ...arc.meta, ...plan.meta };\n log('|...-->| recipe complete: ', recipe.$meta ?? '');\n //log.groupEnd();\n }\n static async evacipate(recipe, runtime, arc) {\n //log.groupCollapsed('evacipating recipe...', recipe.$meta);\n log('|-->...| evacipating recipe: ', recipe.$meta);\n // TODO(sjmiles): this is work we already did\n const plan = new Parser(recipe);\n // `store` work\n // TODO(sjmiles): not sure what stores are unique to this plan\n await StoreCook.evacipate(runtime, arc, plan.stores);\n // `particle` work\n await ParticleCook.evacipate(runtime, arc, plan.particles);\n // seasoning\n // TODO(sjmiles): doh\n //arc.meta = {...arc.meta, ...plan.meta};\n log('|...-->| recipe evacipated: ', recipe.$meta);\n //log.groupEnd();\n }\n static async executeAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.execute(recipe, runtime, arc);\n }\n }\n static async evacipateAll(recipes, runtime, arc) {\n for (const recipe of recipes) {\n await this.evacipate(recipe, runtime, arc);\n }\n }\n}\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nimport { Paths } from '../utils/paths.js';\nimport { logFactory } from '../utils/log.js';\nconst log = logFactory(logFactory.flags.code, 'code', 'gold', '#333');\nconst defaultParticleBasePath = '$arcs/core/Particle.js';\n// acquire particle code\n// `kind` describes the particle\n// `options.code` may simply provide code directly\nexport const requireParticleImplCode = async (kind, options) => {\n const code = options?.code || await fetchParticleCode(kind);\n // TODO(sjmiles): brittle content processing, needs to be documented\n return code.slice(code.indexOf('({'));\n};\nexport const fetchParticleCode = async (kind) => {\n if (kind) {\n return await maybeFetchParticleCode(kind);\n }\n log.error(`fetchParticleCode: empty 'kind'`);\n};\nexport const maybeFetchParticleCode = async (kind) => {\n const path = pathForKind(kind);\n try {\n const response = await fetch(path);\n if (response.ok) {\n return await response.text();\n }\n else {\n throw '';\n }\n }\n catch (x) {\n log.error(`could not locate implementation for particle \"${kind}\" [${path}]`);\n }\n};\nexport const pathForKind = (kind) => {\n if (kind) {\n if (!'$./'.includes(kind[0]) && !kind.includes('://')) {\n kind = `$library/${kind}`;\n }\n if (!kind?.split('/').pop().includes('.')) {\n kind = `${kind}.js`;\n }\n return Paths.resolve(kind);\n }\n return '404';\n};\n// acquire Particle.js\nexport const requireParticleBaseCode = async (sourcePath) => {\n if (!requireParticleBaseCode.source) {\n const path = Paths.resolve(sourcePath || defaultParticleBasePath);\n log('particle base code path: ', path);\n const response = await fetch(path);\n const moduleText = await response.text() + \"\\n//# sourceURL=\" + path + \"\\n\";\n requireParticleBaseCode.source = moduleText.replace(/export /g, '');\n }\n return requireParticleBaseCode.source;\n};\nrequireParticleBaseCode.source = null;\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const PathMapper = class {\n map;\n constructor(root) {\n this.map = {};\n this.setRoot(root);\n }\n add(mappings) {\n Object.assign(this.map, mappings || {});\n }\n resolve(path) {\n let last;\n do {\n path = this._resolve(last = path);\n } while (last !== path);\n return path;\n }\n _resolve(path) {\n const bits = path.split('/');\n const top = bits.shift();\n const prefix = this.map[top] || top;\n return [prefix, ...bits].join('/');\n }\n setRoot(root) {\n if (root.length && root[root.length - 1] === '/') {\n root = root.slice(0, -1);\n }\n this.add({\n '$root': root,\n '$arcs': root\n });\n }\n getAbsoluteHereUrl(meta, depth) {\n // you are here\n const localRelative = meta.url.split('/').slice(0, -(depth ?? 1)).join('/');\n if (!globalThis?.document) {\n return localRelative;\n }\n else {\n // document root is here\n let base = document.URL;\n // if document URL has a filename, remove it\n if (base[base.length - 1] !== '/') {\n base = `${base.split('/').slice(0, -1).join('/')}/`;\n }\n // create absoute path to here (aka 'local')\n let localAbsolute = new URL(localRelative, base).href;\n // no trailing slash!\n if (localAbsolute[localAbsolute.length - 1] === '/') {\n localAbsolute = localAbsolute.slice(0, -1);\n }\n return localAbsolute;\n }\n }\n};\nconst root = import.meta.url.split('/').slice(0, -3).join('/');\nexport const Paths = globalThis['Paths'] = new PathMapper(root);\nPaths.add(globalThis.config?.paths);\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport * from './date.js';\nexport * from './id.js';\nexport * from './log.js';\nexport * from './matching.js';\nexport * from './object.js';\nexport * from './paths.js';\nexport * from './rand.js';\nexport * from './task.js';\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\nexport const computeAgeString = (date, now) => {\n let deltaTime = Math.round((now - date) / 1000);\n if (isNaN(deltaTime)) {\n return `\u2022`;\n }\n let plural = '';\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} second${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 60) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} minute${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 60);\n if (deltaTime < 24) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} hour${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 24);\n if (deltaTime < 30) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} day${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 30);\n if (deltaTime < 12) {\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} month${plural} ago`;\n }\n deltaTime = Math.round(deltaTime / 12);\n if (deltaTime > 1)\n plural = 's';\n return `${deltaTime} year${plural} ago`;\n};\n", "/**\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n/**\n * Perform `action` if `delay` ms have elapsed since last debounce call for `key`.\n *\n * ```\n * // invoke 'task' one second after last time this line executed\n * this.debounceTask = debounce(this.debounceTask, task, 1000);\n * ```\n */\nexport const debounce = (key, action, delay) => {\n if (key) {\n clearTimeout(key);\n }\n if (action && delay) {\n return setTimeout(action, delay);\n }\n};\nexport const async = task => {\n return async (...args) => {\n await Promise.resolve();\n task(...args);\n };\n};\nexport const asyncTask = (task, delayMs) => {\n setTimeout(task, delayMs ?? 0);\n};\n", "/**\n * @license\n * Copyright 2022 Google LLC\n *\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file or at\n * https://developers.google.com/open-source/licenses/bsd\n */\n\nexport * from '../js/Runtime.js';\nexport * from '../js/core/EventEmitter.js';\nexport * from '../js/core/Store.js';\nexport * from '../js/core/Arc.js';\nexport * from '../js/core/Host.js';\nexport * from '../js/core/Decorator.js';\nexport * from '../js/recipe/Chef.js';\nexport * from '../js/recipe/ParticleCook.js';\nexport * from '../js/recipe/StoreCook.js';\nexport * from '../js/recipe/RecipeParser.js';\nexport * as code from '../js/isolation/code.js';\n\nimport * as utils from '../js/utils/utils.js';\nconst {logFactory, Paths} = utils;\nexport {logFactory, Paths, utils};\n\nconst root = import.meta.url.split('/').slice(0, -1).join('/');\nPaths.setRoot(root);\n"], + "mappings": "wOAQO,IAAMA,EAAN,KAAmB,CAEtB,UAAY,CAAC,EACb,kBAAkBC,EAAW,CACzB,OAAO,KAAK,UAAUA,KAAe,KAAK,UAAUA,GAAa,CAAC,EACtE,CACA,KAAKA,KAAcC,EAAM,CACrB,IAAMC,EAAY,KAAK,kBAAkBF,CAAS,EAC9CE,GAAW,SACXA,EAAU,QAAQC,GAAYA,EAAS,GAAGF,CAAI,CAAC,CAEvD,CACA,OAAOD,EAAWG,EAAUC,EAAc,CAEtC,OADkB,KAAK,kBAAkBJ,CAAS,EACxC,KAAKG,CAAQ,EACvBA,EAAS,MAAQC,GAAgB,qBAC1BD,CACX,CACA,SAASH,EAAWG,EAAU,CAC1B,IAAME,EAAO,KAAK,kBAAkBL,CAAS,EACvCM,EAAS,OAAOH,GAAa,SAAYE,EAAK,UAAUE,GAAKA,EAAE,QAAUJ,CAAQ,EAAIE,EAAK,QAAQF,CAAQ,EAC5GG,GAAS,EACTD,EAAK,OAAOC,EAAO,CAAC,EAGpB,QAAQ,KAAK,0BAA2BN,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,UAEjCD,EAAY,KAAK,MAAMA,EAAY,EAAE,EACjCA,EAAY,IACRA,EAAY,IACZC,EAAS,KACN,GAAGD,WAAmBC,UAEjCD,EAAY,KAAK,MAAMA,EAAY,EAAE,EACjCA,EAAY,IACRA,EAAY,IACZC,EAAS,KACN,GAAGD,SAAiBC,UAE/BD,EAAY,KAAK,MAAMA,EAAY,EAAE,EACjCA,EAAY,IACRA,EAAY,IACZC,EAAS,KACN,GAAGD,QAAgBC,UAE9BD,EAAY,KAAK,MAAMA,EAAY,EAAE,EACjCA,EAAY,IACRA,EAAY,IACZC,EAAS,KACN,GAAGD,UAAkBC,UAEhCD,EAAY,KAAK,MAAMA,EAAY,EAAE,EACjCA,EAAY,IACZC,EAAS,KACN,GAAGD,SAAiBC,YAC/B,EC/BO,IAAMC,GAAW,CAACC,EAAKC,EAAQC,IAAU,CAI5C,GAHIF,GACA,aAAaA,CAAG,EAEhBC,GAAUC,EACV,OAAO,WAAWD,EAAQC,CAAK,CAEvC,EACaC,GAAQC,GACV,SAAUC,IAAS,CACtB,MAAM,QAAQ,QAAQ,EACtBD,EAAK,GAAGC,CAAI,CAChB,EAESC,GAAY,CAACF,EAAMG,IAAY,CACxC,WAAWH,EAAMG,GAAW,CAAC,CACjC,ECTA,GAAM,CAAC,WAAAC,GAAY,MAAAC,EAAK,EAAIC,EAG5B,IAAMC,GAAO,YAAY,IAAI,MAAM,GAAG,EAAE,MAAM,EAAG,EAAE,EAAE,KAAK,GAAG,EAC7DC,GAAM,QAAQD,EAAI", "names": ["EventEmitter", "eventName", "args", "listeners", "listener", "listenerName", "list", "index", "l", "logKinds", "errKinds", "fromEntries", "_logFactory", "enable", "preamble", "bg", "color", "kind", "logFactory", "style", "debugLoggers", "logKinds", "errorLoggers", "errKinds", "loggers", "log", "customLogFactory", "id", "logFactory", "assign", "create", "entries", "o", "keys", "values", "nob", "Arc", "EventEmitter", "meta", "surface", "host", "h", "storeId", "store", "isBound", "inputs", "input", "hostId", "inputBindings", "name", "staticInputs", "binding", "storeName", "outputs", "names", "output", "packet", "pid", "eventlet", "request", "result", "shallowUpdate", "obj", "data", "result", "i", "value", "overage", "seen", "key", "shallowMerge", "deepCopy", "datum", "element", "clone", "deepEqual", "a", "b", "type", "aProps", "bProps", "name", "deepUndefinedToNull", "prop", "floor", "pow", "random", "key", "digits", "irand", "range", "arand", "array", "prob", "probability", "log", "logFactory", "values", "entries", "opaqueData", "Decorator", "name", "data", "model", "particle", "item", "models", "maybeDecorate", "maybeFilter", "maybeCollateBy", "decorator", "inputs", "state", "immutableInputs", "deepCopy", "immutableState", "immutableModel", "decorated", "sortByLc", "filter", "impl", "collator", "collation", "collate", "collationToRenderModels", "key", "a", "b", "sort", "collateBy", "keyValue", "$template", "entries", "keys", "customLogFactory", "id", "logFactory", "arand", "Host", "EventEmitter", "eventlet", "particle", "meta", "request", "Decorator", "outputModel", "renderModel", "model", "container", "template", "packet", "inputs", "lastInputs", "deepCopy", "lastOutput", "dirtyBits", "n", "v", "deepEqual", "key", "create", "keys", "stringify", "parse", "DataStore", "EventEmitter", "data", "json", "value", "sorted", "pojo", "key", "ObservableStore", "mutator", "store", "self", "doc", "PersistableStore", "meta", "tags", "tag", "serial", "defaultValue", "Store", "makeId", "pairs", "digits", "delim", "min", "range", "result", "i", "irand", "log", "logFactory", "particleFactoryCache", "storeFactories", "keys", "_Runtime", "EventEmitter", "uid", "makeId", "name", "meta", "surface", "service", "arc", "Arc", "host", "request", "id", "Host", "particleMeta", "particle", "n", "list", "storeId", "store", "onChange", "task", "peerId", "nid", "kind", "x", "code", "particleOptions", "particleIndustry", "registerFactoryPromise", "factoryPromise", "key", "tag", "storeClass", "Store", "Runtime", "__publicField", "log", "logFactory", "entries", "create", "Parser", "recipe", "normalized", "spec", "slotName", "parentName", "key", "container", "stores", "name", "s", "meta", "id", "slots", "parent", "matches", "candidateMeta", "targetMeta", "property", "log", "logFactory", "values", "mapStore", "runtime", "name", "type", "findStores", "criteria", "store", "storeMatches", "other", "typeMatches", "matches", "typeA", "typeB", "baseTypes", "StoreCook", "arc", "stores", "task", "rawMeta", "value", "meta", "cached", "log", "logFactory", "ParticleCook", "runtime", "arc", "particles", "particle", "node", "meta", "spec", "kind", "container", "staticInputs", "inputs", "outputs", "bindings", "binding", "log", "logFactory", "Chef", "recipe", "runtime", "arc", "plan", "Parser", "StoreCook", "ParticleCook", "recipes", "code_exports", "__export", "fetchParticleCode", "maybeFetchParticleCode", "pathForKind", "requireParticleBaseCode", "requireParticleImplCode", "PathMapper", "root", "mappings", "path", "last", "bits", "top", "meta", "depth", "localRelative", "base", "localAbsolute", "Paths", "log", "logFactory", "defaultParticleBasePath", "requireParticleImplCode", "kind", "options", "code", "fetchParticleCode", "maybeFetchParticleCode", "path", "pathForKind", "response", "Paths", "requireParticleBaseCode", "sourcePath", "moduleText", "utils_exports", "__export", "PathMapper", "Paths", "arand", "async", "asyncTask", "computeAgeString", "debounce", "deepCopy", "deepEqual", "deepUndefinedToNull", "irand", "key", "logFactory", "makeId", "matches", "prob", "shallowMerge", "shallowUpdate", "computeAgeString", "date", "now", "deltaTime", "plural", "debounce", "key", "action", "delay", "async", "task", "args", "asyncTask", "delayMs", "logFactory", "Paths", "utils_exports", "root", "Paths"] } diff --git a/pkg/Library/Designer/designer-layout.js b/pkg/Library/Designer/designer-layout.js index b42fe70e..eeead78e 100644 --- a/pkg/Library/Designer/designer-layout.js +++ b/pkg/Library/Designer/designer-layout.js @@ -7,6 +7,9 @@ import {Xen} from '../Dom/Xen/xen-async.js'; import {DragDrop} from '../Dom/drag-drop.js'; import {IconsCss} from '../Dom/Material/material-icon-font/icons.css.js'; +import {logFactory} from '../Core/utils.js'; + +const log = logFactory(logFactory.flags['designer-layout'], 'designer-layout', '#8B8000', '#333'); const {assign} = Object; @@ -183,19 +186,24 @@ export class DesignerLayout extends DragDrop { this.dragKind = 'resize'; this.dragFrom = from; } + // e.stopPropagation(); + // this.rect = this.target && this.getRect(this.target); + this.dragRect = this.rect; + this.dragStarted = false; + // this.restyleSelection(); this.updateOrders(this.target); // This is to select the node right away when pointer is down. this.firePosition(this.target); - this.dragRect = this.rect; } doMove(dx, dy) { if (this.dragRect && this.target) { // grid-snap const snap = rect => DragDrop.snap(rect, GRID_SIZE); // perform drag operation + this.dragStarted = true; const dragRect = this.doDrag(this.dragRect, dx, dy, this.dragKind, this.dragFrom); //const dragRect = this.doDrag(snap(this.dragRect), dx, dy, this.dragKind, this.dragFrom); // install output rectangle @@ -203,6 +211,7 @@ export class DesignerLayout extends DragDrop { // let the boxer adapt to the target end state requestAnimationFrame(() => this.target && this.setBoxStyle(this.boxer, this.getRect(this.target))); this.value = dragRect; + log('fire update-box', this.target.id, this.value); this.fire('update-box'); } } @@ -229,9 +238,13 @@ export class DesignerLayout extends DragDrop { } doUp() { this.dragRect = null; - if (this.target) { + if (this.target && this.dragStarted) { + this.dragStarted = false; + log('drag terminated'); setTimeout(() => { + log('fire update-box', this.target.id); this.fire('update-box'); + log('firePosition', this.target.id); this.firePosition(this.target); }, 100); } diff --git a/pkg/Library/Fields/FieldNodes.js b/pkg/Library/Fields/FieldNodes.js index 3b84ef68..bb64cf54 100644 --- a/pkg/Library/Fields/FieldNodes.js +++ b/pkg/Library/Fields/FieldNodes.js @@ -4,6 +4,8 @@ * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. */ +export * from './MultilineTextFieldNode.js'; + export const TextFieldNode = { $meta: { id: 'Text', diff --git a/pkg/Library/Fields/MultilineTextField.js b/pkg/Library/Fields/MultilineTextField.js new file mode 100644 index 00000000..9bc7bd44 --- /dev/null +++ b/pkg/Library/Fields/MultilineTextField.js @@ -0,0 +1,67 @@ +/** + * @license + * Copyright (c) 2022 Google LLC All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ +({ +update(inputs, state) { + let {value, connectedValue, connectedValue1} = inputs; + if (connectedValue1 && connectedValue1 !== state.lastInputs?.connectedValue1) { + value = connectedValue1; + } + if (connectedValue && connectedValue !== state.lastInputs?.connectedValue) { + value = connectedValue; + } + state.lastInputs = {...inputs}; + state.value = value; + return {value}; +}, +render({label}, {value}) { + return { + label: label ?? '', + value: value ?? '' + }; +}, +onLabelChange({eventlet: {value}}) { + return {label: value}; +}, +onFieldChange({eventlet: {value}}, state) { + state.value = value; + return {value}; +}, +template: html` + + +
+ + : + +
+` +}); diff --git a/pkg/Library/Fields/MultilineTextFieldNode.js b/pkg/Library/Fields/MultilineTextFieldNode.js new file mode 100644 index 00000000..e6a5fab1 --- /dev/null +++ b/pkg/Library/Fields/MultilineTextFieldNode.js @@ -0,0 +1,27 @@ +/** + * @license + * Copyright (c) 2022 Google LLC All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ +export const MultilineTextFieldNode = { + $meta: { + id: 'Text', + category: 'Field' + }, + $stores: { + label: { + $type: 'String', + $value: 'text field' + }, + value: { + $type: 'String', + $value: 'value' + } + }, + field: { + $kind: '$library/Fields/MultilineTextField', + $inputs: ['label', 'value'], + $outputs: ['label', 'value'] + } +}; \ No newline at end of file diff --git a/pkg/Library/Fields/SelectField.js b/pkg/Library/Fields/SelectField.js index d9edee31..af248212 100644 --- a/pkg/Library/Fields/SelectField.js +++ b/pkg/Library/Fields/SelectField.js @@ -31,6 +31,7 @@ template: html` font-size: 75%; border: none; text-align: right; + width: 8em; } [delim] { padding-right: 12px; diff --git a/pkg/Library/Fields/TextField.js b/pkg/Library/Fields/TextField.js index 8de4d4e4..4c02306a 100644 --- a/pkg/Library/Fields/TextField.js +++ b/pkg/Library/Fields/TextField.js @@ -27,7 +27,6 @@ template: html` :host { padding: 0 6px; height: 2em; - Xwidth: 24em; } [label] { background: inherit; @@ -35,6 +34,7 @@ template: html` font-size: 75%; border: none; text-align: right; + width: 8em; } [field] { padding: 6px 9px; diff --git a/pkg/Library/GraphsNodes/ListenerNode.js b/pkg/Library/GraphsNodes/ListenerNode.js new file mode 100644 index 00000000..a5543196 --- /dev/null +++ b/pkg/Library/GraphsNodes/ListenerNode.js @@ -0,0 +1,51 @@ +/** + * @license + * Copyright (c) 2022 Google LLC All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ +export const ListenerNode = { + $meta: { + id: 'ListenerNode', + displayName: 'Listener', + category: 'Media' + }, + $stores: { + mediaDeviceState: { + $type: 'MedaDeviceState', + $value: { + isMicEnabled: false + }, + noinspect: true + }, + mediaDevices: { + $type: '[JSON]', + noinspect: true + }, + transcript: { + $type: 'String', + $value: '', + noinspect: true, + nomonitor: true + } + }, + SpeechRecognizer: { + $kind: '$library/NewMedia/SpeechRecognizer', + $inputs: ['mediaDeviceState'], + $outputs: ['transcript', 'mediaDeviceState'], + $slots: { + device: { + deviceUx: { + $kind: 'Media/DeviceUx', + $inputs: ['mediaDevices', 'mediaDeviceState'], + $outputs: ['mediaDeviceState'] + }, + defaultStream: { + $kind: 'Media/MediaStream', + $inputs: ['mediaDeviceState'], + $outputs: ['mediaDevices'] + } + } + } + } +}; \ No newline at end of file diff --git a/pkg/Library/GraphsNodes/MultilineTextFieldNode.js b/pkg/Library/GraphsNodes/MultilineTextFieldNode.js new file mode 100644 index 00000000..08662f88 --- /dev/null +++ b/pkg/Library/GraphsNodes/MultilineTextFieldNode.js @@ -0,0 +1,36 @@ +/** + * @license + * Copyright (c) 2022 Google LLC All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ +export const MultilineTextFieldNode = { + $meta: { + id: 'MultilineTextFieldNode', + displayName: 'Multiline Text Field', + category: 'Fields' + }, + $stores: { + label: { + $type: 'String', + $value: 'text field' + }, + value: { + $type: 'String', + $value: 'value' + }, + connectedValue: { + $type: 'String', + connection: true + }, + outputValue: { + $type: 'String', + $value: '' + } + }, + field: { + $kind: '$library/Fields/MultilineTextField', + $inputs: ['label', 'value', 'connectedValue'], + $outputs: ['label', {value: 'outputValue'}] + } +}; \ No newline at end of file diff --git a/pkg/Library/GraphsNodes/NodeTypes.js b/pkg/Library/GraphsNodes/NodeTypes.js index 0e62ac2d..c1fddb7d 100644 --- a/pkg/Library/GraphsNodes/NodeTypes.js +++ b/pkg/Library/GraphsNodes/NodeTypes.js @@ -11,13 +11,15 @@ import {DataNode, PersistedDataNode} from './DataNode.js'; import {DisplayNode} from './DisplayNode.js'; import {ImageNode} from './ImageNode.js'; import {CameraNode} from './CameraNode.js'; +import {ListenerNode} from './ListenerNode.js'; import {TextFieldNode} from './TextFieldNode.js'; +import {MultilineTextFieldNode} from './MultilineTextFieldNode.js'; import {SelectFieldNode} from './SelectFieldNode.js'; import {LibrarianNode} from '../Graphs/LibrarianNode.js'; import {GraphRunnerNode} from '../Graphs/GraphRunnerNode.js'; import {ArcNode} from '../App/ArcNode.js'; -import {AudioNode, ImageCompositeNode} from '../NewMedia/Nodes.js'; +import {ImageCompositeNode} from '../NewMedia/Nodes.js'; export const NodeTypes = { JSONataNode, @@ -26,10 +28,11 @@ export const NodeTypes = { DisplayNode, ImageNode, CameraNode, - AudioNode, + ListenerNode, ImageCompositeNode, ArcNode, TextFieldNode, + MultilineTextFieldNode, SelectFieldNode, LibrarianNode, GraphRunnerNode, diff --git a/pkg/Library/Media/DeviceUx.js b/pkg/Library/Media/DeviceUx.js index e015b43f..dd35a9f2 100644 --- a/pkg/Library/Media/DeviceUx.js +++ b/pkg/Library/Media/DeviceUx.js @@ -10,6 +10,8 @@ shouldRender({mediaDevices}) { }, render({mediaDevices, mediaDeviceState}) { const {isCameraEnabled, isMicEnabled, isAudioEnabled, videoDeviceId, audioInputDeviceId, audioOutputDeviceId} = mediaDeviceState; + const showCamera = String(isCameraEnabled !== undefined); + const showSpeaker = String(isAudioEnabled !== undefined); const cameraEnabled = Boolean(isCameraEnabled); const micEnabled = Boolean(isMicEnabled); const audioEnabled = Boolean(isAudioEnabled); @@ -21,10 +23,12 @@ render({mediaDevices, mediaDeviceState}) { videoInputs, audioInputs, audioOutputs, + showCamera, cameraEnabled, cameraLigature: cameraEnabled ? `videocam` : `videocam_off`, micEnabled, micLigature: isMicEnabled ? `mic` : `mic_off`, + showSpeaker, audioEnabled, audioLigature: audioEnabled ? `volume_up` : `volume_off`, }; @@ -91,12 +95,12 @@ template: html`
- {{cameraLigature}} - + {{cameraLigature}} + {{micLigature}} - {{audioLigature}} - + {{audioLigature}} +
diff --git a/pkg/Library/NewMedia/CameraNode.js b/pkg/Library/NewMedia/CameraNode.js index f39a2e4b..b931ed06 100644 --- a/pkg/Library/NewMedia/CameraNode.js +++ b/pkg/Library/NewMedia/CameraNode.js @@ -47,7 +47,7 @@ export const CameraNode = { $outputs: ['stream', 'frame'], $slots: { device: { - deviceUx: DeviceUxRecipe.deviceUx, + deviceUx: DeviceUxRecipe.deviceUx }, capture: { imageCapture: { diff --git a/pkg/Library/NewMedia/Image.js b/pkg/Library/NewMedia/Image.js index a5e6ba49..d0d3ca49 100644 --- a/pkg/Library/NewMedia/Image.js +++ b/pkg/Library/NewMedia/Image.js @@ -11,6 +11,8 @@ update({connectedImage, image}, state) { } else { state.image = image; } + //log('update: connectedImage, image', connectedImage, image); + //log('update: state.image', image); // const bestImage = connectedImage || image; // if (bestImage.url) { // if (!state.image || bestImage.url !== state.image.url) { @@ -18,10 +20,16 @@ update({connectedImage, image}, state) { // } // } }, +render(input, {image}) { + //log('render image: ', image); + return {image}; +}, onCanvas({eventlet: {value}}, state) { + //log('state.image', state.image, value); if (state.image?.url === value?.url) { const image = {...value, version: Math.random()}; state.image = image; + //log('output image w/canvas', image, value); return {image}; } }, diff --git a/pkg/Library/NewMedia/SpeechRecognizer.js b/pkg/Library/NewMedia/SpeechRecognizer.js index d1b61c0b..29cca3dc 100644 --- a/pkg/Library/NewMedia/SpeechRecognizer.js +++ b/pkg/Library/NewMedia/SpeechRecognizer.js @@ -5,13 +5,14 @@ */ ({ render({mediaDeviceState}) { - return {micEnabled: Boolean(mediaDeviceState.isMicEnabled)}; + return {micEnabled: Boolean(mediaDeviceState?.isMicEnabled)}; }, onTranscript({eventlet: {value}, mediaDeviceState}) { - const transcript = value.transcript || value.interimTranscript; - const outputs = {transcript}; + const outputs = value; if (value.transcript) { - assign(outputs, {mediaDeviceState: {...mediaDeviceState, isMicEnabled: false}}); + assign(outputs, { + mediaDeviceState: {...mediaDeviceState, isMicEnabled: false} + }); } return outputs; }, diff --git a/pkg/Library/NewMedia/image-resource.js b/pkg/Library/NewMedia/image-resource.js index 44d3779f..4605c424 100644 --- a/pkg/Library/NewMedia/image-resource.js +++ b/pkg/Library/NewMedia/image-resource.js @@ -6,6 +6,9 @@ */ import {Xen} from '../Dom/Xen/xen-async.js'; import {Resources} from '../App/Resources.js'; +import {logFactory} from '../Core/utils.js'; + +const log = logFactory(logFactory.flags.dom || true, 'image-resource', 'yellow', 'darkgray'); const template = Xen.Template.html`