Package Exports
- @architect/functions
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@architect/functions) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@architect/functions
Runtime helper library for serverless apps built with Architect
Check out the full docs: arc.codes
API
Given:
let arc = require('@architect/functions')The following APIs exists:
arc.events.subscribe(fn)
Used to define a lambda function that will act as an event handler. Event handlers are defined in your application's Architect project manifest file under the @events pragma. The function code for the accompanying handler to each event should use arc.events.subscribe to wrap the handler. For example, given the following project manifest snippet:
@events
concerts... the following file will be initialized representing the event handler for the concerts event, wherein you need to use arc.events.subscribe:
// file: src/events/concerts/index.js
let arc = require('@architect/functions')
module.exports = arc.events.subscribe(function(payload, callback) {
console.log(payload)
callback()
})arc.events.publish(params, callback)
Publishes params.payload to the SNS Topic (event) with name params.name. The params.name parameter should match the event defined under @events. Building on the example we described above, to trigger the concerts event handler, we would set params.name to be concerts.
This allows you to publish events from any function within your application (@app .arc file namespace) to be handled by the event handler.
When running in local/testing mode, will publish the event to the sandbox.
arc.queues.subscribe(params, callback)
Used to define a lambda function that will act as a queue handler. Queue handlers are defined in your application's .arc file under the @queues pragma. The function code for the accompanying handler to each queued item should use arc.queues.subscribe to wrap the handler. For example, given the following .arc file snippet:
@queues
concert-tickets... the following file will be initialized representing the event handler for the concert-tickets queue, wherein you need to use arc.queues.subscribe:
// file: src/queues/concert-tickets/index.js
let arc = require('@architect/functions')
module.exports = arc.queues.subscribe(function(payload, callback) {
console.log(payload)
callback()
})arc.queues.publish(params, callback)
Publishes params.payload to the SQS Queue (queue) with name params.name. The params.name parameter should match the queue defined under @queues. Building on the example we described above, to trigger the concert-tickets queue handler, we would set params.name to be concert-tickets.
This allows you to publish to queues from any function within your application (@app .arc file namespace) to be handled by the queue handler.
When running in local/testing mode, will publish the event to the sandbox.
arc.static(assetPath, options)
Returns the fully-qualified URI of a static asset for the project-relative assetPath parameter. Takes into account:
- What environment (testing, staging, production) we are running in.
- Whether fingerprinting is enabled.
- Whether the override environment variable
ARC_STATIC_BUCKETis present.
options is an object with the following currently-supported properties:
stagePath: boolean, prepends/stagingor/productionto the asset path; useful if the current app is being run on an naked (non-domain-mapped) API Gateway
arc.tables(callback)
Returns an object that can be used to access data in database tables as defined under @tables in your .arc file. For example, given the following .arc file snippet:
@tables
accounts
accountID *String
messages
msgID *StringRunning the following code:
let data = await arc.tables()Would yield the following objects:
data.accounts: reference to theaccountstabledata.messages: reference to themessagestable
.. which contain the following methods:
delete(key, callback): deletes the record from the table with keykeyand invokescallbackwith the resultget(key, callback): retrieves the record from the table with keykeyand invokescallbackwhen completeput(item, callback): addsitemto the table and invokescallbackwith the item when completequery(params, callback): queries the table usingparamsand invokescallbackwith the resultscan(params, callback): scans the table usingparamsand invokescallbackwith the resultupdate(params, callback): updates an item in the table usingparamsand invokescallbackwhen complete
